trovit / reffects-store

A state container for React based in reffects
4 stars 0 forks source link

Avoid run all the subscription flow for components not passing mapStateToProps as argument #4

Open mariosanchez opened 5 years ago

mariosanchez commented 5 years ago

In some edge cases we are using subscribe function only to inject props, yet not for subscribing it to the state. In those cases we aren't passing by mapStateToProps.

Despite we consider it an anti-pattern, because we could simply compose the component in order to achieve that, it will be a improvement to not execute all the subscription flow if no mapStateToProps is passed by in the subscribe function.

Now we are passing by an empty fucntion:

subscribe(Component, () => {}, { myInjectedPropr: 'Hi there' });

This should allow to do this:

subscribe(Component, null, { myInjectedPropr: 'Hi there' }`);
trikitrok commented 5 years ago

It's a nice idea. If it were possible, I'd would prefer to have a function with two arities instead of passing a null though.

alexhoma commented 5 years ago

The main point of this would be to not execute the mapStateToProps if the component does not need to be subscribed to the state. But I can't imagine how to check this without executing the function and checking its returned values. With null will be easier to check it. Anyway, I'd prefer to use null instead of () => {}. :stuck_out_tongue: