Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RiotControl compatible with AMD / Commonjs loaders #16

Open
duongphuhiep opened this issue Aug 5, 2015 · 0 comments
Open

Make RiotControl compatible with AMD / Commonjs loaders #16

duongphuhiep opened this issue Aug 5, 2015 · 0 comments

Comments

@duongphuhiep
Copy link

I picked a UMD code snippet

No need to shim RiotControl in requirejs anymore

What do you think about it?

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define([], factory);
  } else if (typeof module === 'object' && module.exports) {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like environments that support module.exports,
    // like Node.
    module.exports = factory();
  } else {
    // Browser globals (root is window)
    root.returnExports = factory();
  }
}(this, function () {

  var RiotControl = {
    _stores: [],
    addStore: function(store) {
      this._stores.push(store);
    }
  };

  ['on','one','off','trigger'].forEach(function(api){
    RiotControl[api] = function() {
      var args = [].slice.call(arguments);
      this._stores.forEach(function(el){
        el[api].apply(null, args);
      });
    };
  });

  return RiotControl;

}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant