janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
241 stars 58 forks source link

UMD #17

Closed IceOnFire closed 8 years ago

IceOnFire commented 8 years ago

IMHO the best way to support globals, Node, and AMD is by conforming to the UMD API (https://github.com/umdjs/umd).

I tried wrapping your library in this IIFE

;(function(root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['q'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(require('q'));
  } else {
    root.o = factory(root.Q);
  }
}(this, function(Q) {
  function o(res) {
  ...
  }

  return o;
}));

and it works like a charm. What do you think?

Antony

janhommes commented 8 years ago

Awesome. Thanks for sharing this, I will definitely add this.

However I will maybe need until end of this week. But if you want to contribute, I will also accept pull request.

IceOnFire commented 8 years ago

Hi Jan,

I applied UMD support in the pull request above. I messed up a little with commits and failing tests, but everything should be ok now.

Antony

janhommes commented 8 years ago

Added in v0.2.1 - #21