Sha256: 33c1cce6285d5e0da7d4d7223be827f7cbf877d1fd7a86b85fdb6f6c7bd33eea

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents


/* This optional extension re-enables the React mixin system for plain JS
 * classes, e.g. ES6 classes, Backbone classes, ES3 module pattern classes
 * You require the extension like `//= require revelry/extensions/mixins` and
 * then you just use appComponent and revComponent like normal.
 * Internally, this works by wrapping the appComponent and revComponent methods
 * in a function closure which actually does the mixing in, since React punts.
 */

(function(Rev) {

  function mixinListForObject(object) {
    var mixinList = object.mixins || [];
    mixinList.push(Rev.Mixins.Core);
    return _.uniq(mixinList);
  }

  function forEachMixin(object, fn) {
    var mixin, i, l;
    var mixinList = mixinListForObject(object);
    l = mixinList.length;
    for(i = 0; i < l; i++) {
      mixin = mixinList[i];
      fn(mixin);
    }
  }

  function decorateComponentMethod(componentMethod) {
    return function(name, object) {
      var componentClass = (componentMethod.bind(Rev))(name, object);
      if(typeof object === 'function') {
        // ES6 class
        forEachMixin(object, function(mixin){
          Rev.__mixSpecIntoComponent(componentClass, mixin);
        });
      }
    }
  }

  Rev.appComponent = decorateComponentMethod(Rev.appComponent);
  Rev.registerComponent = decorateComponentMethod(Rev.registerComponent);

})(Rev);

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
revelry_core-0.1.12.4 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.12.2 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.11.6 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.10.1 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.10.0 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.9.1 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.9.0 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js
revelry_core-0.1.8.0 spec/dummy/tmp/jasmine/assets/revelry/extensions/mixins.self.js