Code Monkey home page Code Monkey logo

Comments (15)

acdlite avatar acdlite commented on May 18, 2024

@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.

tappleby avatar tappleby commented on May 18, 2024

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.

acdlite avatar acdlite commented on May 18, 2024

@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.

tappleby avatar tappleby commented on May 18, 2024

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.

acdlite avatar acdlite commented on May 18, 2024

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.

tappleby avatar tappleby commented on May 18, 2024

Ah thats not so bad then. I was picturing the reduce using something like (...stores) => stores.reduce(...).

from flummox.

acdlite avatar acdlite commented on May 18, 2024

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.

tappleby avatar tappleby commented on May 18, 2024

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.

acdlite avatar acdlite commented on May 18, 2024

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.

tappleby avatar tappleby commented on May 18, 2024

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.

gaearon avatar gaearon commented on May 18, 2024

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.

acdlite avatar acdlite commented on May 18, 2024

@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.

acdlite avatar acdlite commented on May 18, 2024

@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.

gaearon avatar gaearon commented on May 18, 2024

Oh. I just realized why you're using strings there :-).

from flummox.

acdlite avatar acdlite commented on May 18, 2024

Added in #73 by @tappleby. Will be released as part of 3.0.

from flummox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.