The mixin technique is explained as a code reusable way to define the react components in React official document. It can make the different components share some common functionality. The mixin can overwrite the life cycle methods. If several mixins define the same life cycle method, all these methods are guaranteed to be called in the order mixins are listed.
Define several SpecPolicy.
[
DEFINE_ONCE,
DEFINE_MANY, // means can be defined by either the component class or mixin object, but the methods must return =void=.
OVERRIDE_BASE,
DEFINE_MANY_MERGED
]
Define object ReactClassInterface to set the life cycle functions spec policy.
{
mixins: SpecPolicy.DEFINE_MANY,
statics: SpecPolicy.DEFINE_MANY,
}
mixSpecIntoComponent method to do the follow things.MIXINS_KEY to store the exist mixins.mixSpecIntoComponent if the current mixin has its own mixins.validateMethodOverride : get the method spec policy and check if any of them violate the policy;ReactClassInterface method, and not defined yet, and a props autobind of the current mixin is not false, then the function will be paste to the component's prototype and a hash map property of the prototype called __reactAutoBindMap.ReactClassInterface method or not a function or the mixin autobind is false, then the field will only be paste to the component's prototype.shouldComponentUpdate.
To think in React is to find the minimal amount of state necessary to represent your app, and calculate everything based on that. This is because state is unpredictable. Props are, for the most part, derived from other props and state, but state can be anything.
mixSpecIntoComponent(Constructor, mixins[i]);function mixSpecIntoComponent(Constructor, spec) {...}