javascript - Handling collection changes in React -


we're rolling out our own mutable collection class use within react list component. since actual contents rendered managed separately collection (which inject in component via props), we're faced 2 design doubts:

  • whether collection object should held in state or, instead, kept in props or instance property of component (given can handle own state);

  • what idiom triggering rendering on collection changes be.

we've been brainstorming best way this. collection's mutation methods return promise resolves collection itself; if keep collection in state, idea done() promise (in coffeescript)?

@state.collection_object.add_an_item('foo').done(   (mutated_collection_object) => @setstate(collection_object: mutated_collection_object) ) 

i'd insight on approaches you've taken/seen far.

holding collection in state can messy pretty quickly, props feel it's worse. have considered holding collection outside component entirely? i've gone route.

you can trigger synthetic events upon change node's eventemitter, listen changes within component in order trigger re-render. plus can move code out of component more deals collection itself.

i found simple example, it's of help. luck!

http://mwdesilva.com/posts/event-driven-react-js-components-via-an-event-emitter-mixin


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -