Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80517 views
1
'use strict';
2
3
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };
4
5
module.exports = fluxMixin;
6
/**
7
* fluxMixin
8
*
9
* Exports a function that creates a React component mixin. Implements methods
10
* from reactComponentMethods.
11
*
12
* Any arguments passed to the mixin creator are passed to `connectToStores()`
13
* and used as the return value of `getInitialState()`. This lets you handle
14
* all of the state initialization and updates in a single place, while removing
15
* the burden of manually adding and removing store listeners.
16
*
17
* @example
18
* let Component = React.createClass({
19
* mixins: [fluxMixin({
20
* storeA: store => ({
21
* foo: store.state.a,
22
* }),
23
* storeB: store => ({
24
* bar: store.state.b,
25
* })
26
* }]
27
* });
28
*/
29
30
var _PropTypes = require('react');
31
32
var _Flux = require('../Flux');
33
34
var _instanceMethods$staticProperties = require('./reactComponentMethods');
35
36
var _assign = require('object-assign');
37
38
var assign = _interopRequire(_assign);
39
40
function fluxMixin() {
41
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
42
args[_key] = arguments[_key];
43
}
44
45
function getInitialState() {
46
this.initialize();
47
return this.connectToStores.apply(this, args);
48
}
49
50
return assign({ getInitialState: getInitialState }, _instanceMethods$staticProperties.instanceMethods, _instanceMethods$staticProperties.staticProperties);
51
}
52
53
;
54