You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of using mixins for shouldComponentUpdate we can just add the shouldComponentUpdate method if it is not defined by the user in this place:
function addMixins(config) {
config.mixins = config.mixins || [];
config.mixins.push(WithPureRenderMixin);
config.mixins.push(WithCursorLinkingMixin);
config.mixins.push(WithTransactMixin);
config.mixins.push(WithCommandPublisherMixin);
config.mixins.push(WithEventPublisherMixin);
config.mixins.push(WithEventListenerMixin);
}
function createPureClass(name,component) {
Preconditions.checkHasValue(name,"The name attribute is mandatory: this helps to debug compoennts!")
Preconditions.checkHasValue(component,"The config attribute is mandatory!")
Preconditions.checkCondition(!component.initialState,"Pure components should not have any local state, and thus no initialState attribute");
Preconditions.checkCondition(!component.shouldComponentUpdate,"shouldComponentUpdate is already implemented for you");
Preconditions.checkCondition(component.render,"render() must be implemented");
Preconditions.checkCondition(component.propTypes,"propTypes must be provided: this is the component interface!");
// Unfortunately, the displayName can't be infered from the variable name during JSX compilation :(
// See http://facebook.github.io/react/docs/component-specs.html#displayname
component.displayName = name;
// Because React's displayName is not easy to obtain from a mixin (???)
component.getDisplayName = function() { return name };
addMixins(component);
return React.createClass(component);
}
exports.createPureClass = createPureClass;
Also we want to abstract the use of React's context feature from the user as it is still undocumented, so we can add a method to get access to AtomReact context methods, probably by merging contextTypes required by AtomReact to contextTypes defined by the user.
Also it would be nice to work around the problem of JSX's displayName inference.
The fact that we use a custom class factory means that JSX can't infer the displayName anymore and to have a displayName it is required to use something like:
var Footer = AtomReact.createPureClass("Footer",{
...
});
Can we make the inference work wiith a custom class factory?
The text was updated successfully, but these errors were encountered:
React libs tends to use mixins but it would be better to not use them anymore.
See
https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750
Instead of using mixins for shouldComponentUpdate we can just add the shouldComponentUpdate method if it is not defined by the user in this place:
Also we want to abstract the use of React's context feature from the user as it is still undocumented, so we can add a method to get access to AtomReact context methods, probably by merging contextTypes required by AtomReact to contextTypes defined by the user.
Also it would be nice to work around the problem of JSX's displayName inference.
The fact that we use a custom class factory means that JSX can't infer the displayName anymore and to have a displayName it is required to use something like:
Can we make the inference work wiith a custom class factory?
The text was updated successfully, but these errors were encountered: