Comments (15)
@martintietz That's a good idea. Basically a reduce operation. It would require a bit of refactoring, though, since getStoreState()
assumes a one-to-one relationship between stores and state getters.
from flummox.
Will this still need to support the 1 call per store to the stateGetter
function?
If so one option could be to check the number of arguments on the stateGetter
using Function.length (similar to how react-router does with willTransitionTo
)
from flummox.
@tappleby Not sure I understand your question. The single key and object forms of connectToStores()
will continue to work the exact same way. This would only affect the array form.
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.
from flummox.
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 FluxMixin(['storeA', 'storeB', 'storeC'])
, but that can be handled with a state getter that performs the reduce you mentioned.
My only issue with an array of stores instead of the spread is its not as clean when accessing the stores inside the getter.
from flummox.
If you're not dealing with them individually, you'd rather them be an array so you can do stores.reduce()
. It's mostly an aesthetic thing, though, because with ES6, you can always do let stores = Array.from(arguments)
, or conversely, let [ storeA, storeB, storeC ] = stores
.
from flummox.
Ah thats not so bad then. I was picturing the reduce using something like (...stores) => stores.reduce(...)
.
from flummox.
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.
from flummox.
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:
function (stores) {
let [ storeA, storeB, storeC ] = stores;
...
}
Also for those not using ES6 it gets a bit more verbose.
from flummox.
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.
from flummox.
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 arguments
for reduce. not sure about TypeScript of CoffeeScript.
from flummox.
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!)
from flummox.
@gaearon Destructuring is what I was suggesting above, except for arrays, not objects.
There are three ways you can call FluxMixin / connectToStores()
. In the object form, the keys map to individual store getters, so you don't need the second parameter. We're discussing changing the array form so that you can specify a single state getter that is passed all the stores, as either an array or spread across the args.
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".
from flummox.
@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) { ... })
from flummox.
Oh. I just realized why you're using strings there :-).
from flummox.
Added in #73 by @tappleby. Will be released as part of 3.0.
from flummox.
Related Issues (20)
- how to get a child component input value HOT 1
- Missing getActionsAsObject from Actions HOT 5
- Incorrect params passed to async begin handler HOT 1
- More topic guides needed in doc HOT 1
- Context differs problem
- Do not pass flux prop to components wrapped with `connect` HOT 6
- Use Redux HOT 6
- Explanation in README as to why a switch to Redux should be made HOT 5
- Import flummox/component fails with 4.0.0-rc1 HOT 1
- unable to make flummox work with react-router 1.0.0-beta3 HOT 2
- Actions.js grabs all console logs HOT 4
- Wrong link in why-flux-component-is-better-than-flux-mixin.md
- Considering the numbers HOT 1
- Support for React 0.14 HOT 17
- How to only use custom stateGetter for subset of subscribed stores HOT 1
- Maintain module? HOT 4
- FluxComponent does not work on IE10 HOT 24
- Flummox 3.6 is incompatible with IE8 HOT 3
- TestUtils removed from NPM HOT 2
- Deprecation warning with React 15.5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flummox.