-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
connectToStores with an Array of stores #43
Comments
@martintietz That's a good idea. Basically a reduce operation. It would require a bit of refactoring, though, since |
Will this still need to support the 1 call per store to the If so one option could be to check the number of arguments on the |
@tappleby Not sure I understand your question. The single key and object forms of Only change I'd make to @martintietz's suggested API above is to pass an array of stores to the getter function, rather than spread them across as arguments. |
Sorry, my question was when using the array form would there be some cases where the user wants the stateGetter to be called multiple times (once for each store)? Initially I was thinking multiple calls would be required when using the defaultStateGetter My only issue with an array of stores instead of the spread is its not as clean when accessing the stores inside the getter. |
If you're not dealing with them individually, you'd rather them be an array so you can do |
Ah thats not so bad then. I was picturing the reduce using something like |
Yeah, even better. I still kinda like the symmetry of the taking in an array of store keys and passing an array of stores, but either way makes sense to me. |
Yeah I do like the symmetry aspect. from a functionality point of view, at least for my use cases, accessing the stores individually will be a lot more common then performing a reduce so it could get repetitive having to do:
Also for those not using ES6 it gets a bit more verbose. |
You could actually also do this: function ([storeA, storeB, storeC]) {
...
} I could really go either way on this. Can you think of a similar api from another library perhaps? I know there must be one, I just can't think of any off the top of my head. |
That works. I used to have issues with that syntax and jstransform but appears to be resolved now (should probably just switch to babel anyways). I cant think of a similar api offhand, will see if anything comes up in the morning. With the ES6 syntax, I'm impartial to either. For ES5 its a bit cleaner as separate parameters or |
What about object destructuring? FluxMixin({ storeA, storeB, storeC }, function({ storeA, storeB, storeC }, props) {
...
}) (Pardon if I misunderstand how this mixin works and you're discussing something else entirely!) |
@gaearon Destructuring is what I was suggesting above, except for arrays, not objects. There are three ways you can call FluxMixin / It's this: FluxMixin(['storeA', 'storeB', 'storeC'], function(storeA, storeB, storeC) { ... } versus FluxMixin(['storeA', 'storeB', 'storeC'], function(stores) { ... } ES6 makes the difference mostly cosmetic — in the first form you could use spread to transform the args into an array, and in the second form you could use array destructuring to transform the array into "args". |
@gaearon Oh now I think I see what your actual point was. Now that we've discussed passing props to state getters over in #31, the array form really is necessary so we can pass extra parameters at the end: FluxMixin([ 'storeA', 'storeB', 'storeC' ], function([ storeA, storeB, storeC ], props) { ... }) |
Oh. I just realized why you're using strings there :-). |
Right now there is an issue if you are using the FluxMixin (the same should be true for FluxComponent) with an array and a single stateGetter like this:
In this case the callback will be called 3 times (each time with one with the stores as an argument). It would be better if it could be called only one time with all 3 stores being arguments of the callback. So that we could use the mixin like this:
This would need some refactoring inside the
connectToStores
andgetStoreState
functions.The text was updated successfully, but these errors were encountered: