Skip to content

Commit 0a186fa

Browse files
author
Hector Virgen
committed
Adds support for commonjs (e.g. WebPack)
Only fixes the vanilla adapter. The angular adapter may still be busted when using WebPack.
1 parent 5fecad6 commit 0a186fa

File tree

11 files changed

+141
-123
lines changed

11 files changed

+141
-123
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function(grunt) {
3030
}
3131
},
3232
vanilla: {
33-
src: ['lib/http_adapter/vanilla.js', 'lib/index.js', 'lib/vanilla.js'],
33+
src: ['lib/http_adapter/vanilla.js', 'lib/index.js'],
3434
dest: 'api-client.js'
3535
}
3636
},

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ app.get('/', function(req, res) {
5656
```js
5757
<script src="bower_components/tagged-api/tagged-api-min.js"></script>
5858
<script>
59+
var adapter = new TaggedApiVanillaAdapter(XMLHttpRequest, Promise);
5960
var api = new TaggedApi('/api.php', {
6061
session_id: 'abc123' // Session cookie ID from `document.cookie`
61-
});
62+
}, adapter);
6263
</script>
6364
```
6465

api-angular-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api-angular.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
var TaggedApi = function(endpoint, options, http) {
2525
this._endpoint = endpoint;
2626

27-
// Default to the vanilla adapter should clients not pass adapter
28-
this._http = (typeof http !== 'undefined') ? http : new VanillaAdapter(context.XMLHttpRequest, context.Promise || require('bluebird'));
27+
// HTTP adapter to perform HTTP requests
28+
this._http = http;
2929

3030
// API calls that are made within a single JS execution frame will be added
3131
// to the queue and processed as a whole on the next tick.
@@ -259,7 +259,7 @@
259259
this._events[stat].push(callback);
260260
};
261261

262-
TaggedApi.middleware = function(url, options) {
262+
var middleware = function(url, options) {
263263
var NodeAdapter = require('./http_adapter/node');
264264
var http = new NodeAdapter();
265265

@@ -420,11 +420,12 @@
420420
return obj1;
421421
}
422422

423-
if (typeof exports !== 'undefined') {
424-
// We're in a nodejs environment, export this module
425-
module.exports = TaggedApi;
423+
if (typeof module !== 'undefined' && module.exports) {
424+
// We're in a commonjs environment
425+
module.exports.Client = TaggedApi;
426+
module.exports.middleware = middleware;
426427
} else {
427-
// We're in a browser environment, expose this module globally
428+
// All other environments, expose TaggedApi globally
428429
context.TaggedApi = TaggedApi;
429430
}
430431
})();

0 commit comments

Comments
 (0)