Giter Club home page Giter Club logo

Comments (7)

mridgway avatar mridgway commented on July 21, 2024

In Flux, the store should never have direct access to the component, just like in MVC the models should never reference the views. Any information that you need the store to have access to should be passed to the dispatch() method. The component should only be listening to changes from the store: store.on('change', () => { this.setState(store.getState()); })

from dispatchr.

jeromecovington avatar jeromecovington commented on July 21, 2024

@mridgway - Am I misunderstanding Promises? It seems that I cannot return the object containing the updates for state from the Promise within GET_STATE, but just another Promise?

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

Stores are EventEmitters, so you have the component add a change listener and when you call this.emitChange() it tells the listener that the store content has changed. Promises are not needed within stores since handlers are completely synchronous.

from dispatchr.

jeromecovington avatar jeromecovington commented on July 21, 2024

All good points, and appreciated. Although you may notice in the example above that the data being set relies on a Promise being resolved from an asynchronous fetch. So in that case I do still think we need a way to affect state from within the then.

from dispatchr.

jeromecovington avatar jeromecovington commented on July 21, 2024

Looking at this again, I think I see your point regarding store.on('change', () => { this.setState(store.getState()); })

But if you could please expand on that, as I don't immediately see a way to access ShowsListStore for on() or getState()

But overall I think the point is to fire the action from the component, allow the store to make its async fetch call and update an object property of the store, say stateObj, with the desired state changes, and emit a change. Following that, the component would listen for the store's change and call ShowsListStore.getState() which would be a public method which would return stateObj.

So again, if all that makes sense, it is then a matter of being able to access on() and getState() from ShowsListStore.

from dispatchr.

jeromecovington avatar jeromecovington commented on July 21, 2024

I was just able to implement the above. Thanks for responding to the issue, and not only reiterating why direct access to the component from the store is an anti-pattern, but clearly outlining a way out.

from dispatchr.

mridgway avatar mridgway commented on July 21, 2024

Glad you figured it out @jeromecovington! Sorry for the delay in responses. If you have any other issues you may be able to get faster responses in our #fluxible channel on Reactiflux.

from dispatchr.

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.