Replaces Marty.StateMixin
.
TODO
PureRenderMixin
?
// container.js
let Component = require('./component.react');
let Mixin = require('./mixin');
let PureRenderMixin = require('react/addons').PureRenderMixin;
let React =require('react');
let Container = React.createClass({
mixins: [
Mixin,
PureRenderMixin
],
render: function() {
return <Component {...this.state.toObject()} />;
}
});
module.exports = Container;
// mixin.js
let Store = require('./store');
let Marty = require('marty');
let Immutable = require('Immutable');
let Mixin = Marty.createStateMixin({
listenTo: [Store],
getState: function() {
return Immutable.Map({
some: Store.getSome()
});
}
});
module.exports = Mixin;
for:
// container.js
import Component from './component.react'
import Store from './store'
import Immutable from 'Immutable'
import React from 'react'
let Container = Marty.createContainer(Component, {
listenTo: Store,
fetch: {
some() { return Store.some }
}
}
export default Container
Getting something like this?
An error occured when handling the DONE state of a fetch TypeError: type.toUpperCase is not a function {stack: (...), message: "type.toUpperCase is not a function"}message: "type.toUpperCase is not a function"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: Errorwhen @ when.js:45render @ createContainer.js:65ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext @ ReactCompositeComponent.js:767ReactCompositeComponentMixin._renderValidatedComponent @ ReactCompositeComponent.js:793ReactPerf.measure.wrapper @ ReactPerf.js:70ReactCompositeComponentMixin.mountComponent @ ReactCompositeComponent.js:227ReactPerf.measure.wrapper @ ReactPerf.js:70ReactReconciler.mountComponent @ ReactReconciler.js:38ReactMultiChild.Mixin.mountChildren @ ReactMultiChild.js:192ReactDOMComponent.Mixin._createContentMarkup @ ReactDOMComponent.js:287ReactDOMComponent.Mixin.mountComponent @ ReactDOMComponent.js:197ReactReconciler.mountComponent @ ReactReconciler.js:38ReactCompositeComponentMixin.mountComponent @ ReactCompositeComponent.js:237ReactPerf.measure.wrapper @ ReactPerf.js:70ReactReconciler.mountComponent @ ReactReconciler.js:38ReactMultiChild.Mixin._mountChildByNameAtIndex @ ReactMultiChild.js:400ReactMultiChild.Mixin._updateChildren @ ReactMultiChild.js:306ReactMultiChild.Mixin.updateChildren @ ReactMultiChild.js:251ReactDOMComponent.Mixin._updateDOMChildren @ ReactDOMComponent.js:466ReactDOMComponent.Mixin.updateComponent @ ReactDOMComponent.js:317ReactDOMComponent.Mixin.receiveComponent @ ReactDOMComponent.js:301ReactReconciler.receiveComponent @ ReactReconciler.js:97ReactCompositeComponentMixin._updateRenderedComponent @ ReactCompositeComponent.js:726ReactCompositeComponentMixin
You probably missed the Component
in your createContainer
call.
Check out that it reads:
let Container = Marty.createContainer(Component, {
// ...
});
instead of:
let Container = Marty.createContainer({
// ...
});