Comments (6)
Is each item in the list listening for the store changes or just the parent? Ideally it's just the parent that is listening for changes and then passing the item details into the list items via props. That way you don't need to worry about ids at all, React will only update the single item in the list.
from dispatchr.
yes, i was thinking of a scenario where each item listens to the store changes. let me try to explain a bit more. lets say items get loaded once into the items store, and there are different components which use a subset of these items.
say for example there's one parent Items renderer which renders item 1 , item 4, item 5
there's another parent items renderer which renders item 3, item 2
so if both the parents are listening to the ItemsStore, even if there's an item that got changed which the parent renderer doesn't care about, it would get notified and it would try to re-render it's children (unless react is smart enough to ignore that? ). But if it's just the items themselves that's listening we can avoid that.
also it looks cleaner to attach the listener in each item, so that the parents don't have to worry about listening to stores and making sure it's children are updated. all that the parent will have to do is to put in an item component and pass in an item id.
from dispatchr.
personally 👍 for the ability to attach an optional payload to the emitChange
method on stores.
Though technically you can "get around this" now since the stores extend EventEmitter
which does support emitting events with arbitrary payloads.
But then you have to manually manage adding/removing the store listener yourself in your component.
For the example @sfj2 provides though, I was thinking that the flux way would be to:
Not try to optimize, just render and trust React to do the right thing. BUT if performance is a bottle-neck, and you were careful to treat state
like the React docs told you, then you can boost perf by implementing a shouldComponentUpdate
method on your component(s).
So the idea would be that those individual components would return false
in shouldComponentUpdate
if they notice that their new props
aren't different from their old props
.
thoughts on that approach @mridgway?
from dispatchr.
@koulmomo lets assume figuring out shouldComponentUpdate ourselves is going to be difficult (like say the props is not a simple data structure) , then having the id of the item that was changed as a payload would make it so easy.
from dispatchr.
so if both the parents are listening to the ItemsStore, even if there's an item that got changed which the parent renderer doesn't care about, it would get notified and it would try to re-render it's children (unless react is smart enough to ignore that? ). But if it's just the items themselves that's listening we can avoid that.
It sounds like the parent is already determining which children to render from the list, so it seems like the parent can do a check to see if the child items differ in shouldComponentUpdate
and which would then cancel the re-render if they do not differ.
Immutable data libraries would helper he as well. You'd be able to check whether a whole object has changed just by doing simple equality checks.
It's not recommended to have too many components listening to stores as you'll probably run into performance concerns with all of the listeners. Try to identify which components in your hierarchy should be "Controller Views" and keep them in control of listening for changes and then pass the data down as props.
Let React handle the grunt work of whether or not it should update and then implement shouldComponentUpdate
where you see bottlenecks.
from dispatchr.
With all of this said, I'm fine with allowing to pass payloads into change event.
from dispatchr.
Related Issues (20)
- Investigate Synchronous Dispatching
- Investigate replay-based rehydration HOT 8
- Handler definitions as functions to promote a sort of Revealing Module Pattern
- Add helper functions to Readme
- Bowerify the dispatchr HOT 3
- Encourage passing constructors to getStore and waitFor instead of strings HOT 1
- Ability to have handler for all actions HOT 4
- React errors caused by BaseStore emit do not reach the console HOT 3
- Pull `/utils/BaseStore.js` into it's own module HOT 2
- Does createStore support mixing in event handlers? HOT 3
- Introduce store method `shouldDehydrate` to disable dehydration for a store HOT 2
- Errors during action handlers HOT 5
- require('util'), why? HOT 19
- Why the Dispatcher don't return the class directly? HOT 11
- Throw an error if actionName passed to Dispatcher#dispatch is undefined HOT 4
- docblock incorrectly mentions queueing
- Tie together multiple actions of one async operation HOT 2
- createStore does not expose store in dehydrated context.dispatcher.stores HOT 3
- Unable to affect state asynchronously from store, apply component `this` to handler function? HOT 7
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 dispatchr.