(react, noLongerUsed, extend)
| 11 | */ |
| 12 | var _react, _defined = false; |
| 13 | function defineReact(react, noLongerUsed, extend) |
| 14 | { |
| 15 | var proto, _extend; |
| 16 | |
| 17 | // if no Reflux object is yet available then return and just wait until defineReact is called manually with it |
| 18 | try { |
| 19 | _react = react || _react || React; |
| 20 | _extend = extend || _react.Component; |
| 21 | } catch (e) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | // if Reflux and React aren't present then ignore, wait until they are properly present |
| 26 | // also ignore if it's been called before UNLESS there's manual extending happening |
| 27 | if (!_react || !_extend || (_defined && !extend)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | // ----------- BEGIN Reflux.Component ------------ |
| 32 | /** |
| 33 | * Reflux.Component: |
| 34 | * An implementation for idiomatic React.js classes that mix with |
| 35 | * Reflux stores. To utilize extend Reflux.Component instead of |
| 36 | * React.Component. Then you may hook any Reflux store that has a |
| 37 | * `this.state` property containing its state values to the component |
| 38 | * via `this.store` or an Array of Reflux stores via `this.stores` in |
| 39 | * the component's constructor (similar to how you assign initial state |
| 40 | * in the constructor in ES6 style React). The default values of the |
| 41 | * stores will automatically reflect in the component's state, and any |
| 42 | * further `trigger` calls from that store will update properties passed |
| 43 | * in the trigger into the component automatically. |
| 44 | */ |
| 45 | var RefluxComponent = function(props, context, updater) { |
| 46 | _extend.call(this, props, context, updater); |
| 47 | }; |
| 48 | |
| 49 | // equivalent of `extends React.Component` or other class if provided via `extend` param |
| 50 | Reflux.utils.inherits(RefluxComponent, _extend); |
| 51 | |
| 52 | proto = RefluxComponent.prototype; |
| 53 | |
| 54 | /** |
| 55 | * this.storeKeys |
| 56 | * When this is a falsey value (null by default) the component mixes in |
| 57 | * all properties from the stores attached to it and updates on changes |
| 58 | * from all of them. When set to an array of string keys it will only |
| 59 | * utilized state property names of those keys in any store attached. This |
| 60 | * lets you choose which parts of stores update the component on a component- |
| 61 | * by-component basis. If using this it is best set in the constructor. |
| 62 | */ |
| 63 | proto.storeKeys = null; |
| 64 | |
| 65 | // on the mounting of the component that is where the store/stores are attached and initialized if needed |
| 66 | proto.componentWillMount = function () { |
| 67 | // if there is a this.store then simply push it onto the this.stores array or make one if needed |
| 68 | if (this.store) { |
| 69 | if (Array.isArray(this.stores)) { |
| 70 | this.stores.unshift(this.store); |
nothing calls this directly
no test coverage detected