From what I've read the pattern is the Components pass data to the Actions which Pass to the Store whose value changes trigger updates in Components that subscribe to the Stores. My question is how to "react" to these triggered updates in the form of a notification? ( ie a successfully saved notification )
Ie do I add logic to the render of this notification component that only displays itself if there is a some flag attribute in the object that its subscribed to? Then deletes itself after a time. This sounds wrong.
UPDATE
Thanks to Hannes Johansson I think I have a better grasp of a pattern. What I have working is the following:
Component passes data through action to the Store
The Store interacts with the api and adds a flag to the model that the component is now notified of an updated model.
createItem: function (item) { $.ajax({ url: '/items', method: 'POST', data: item, success: function (item) { CurrentBrandActions.addCampaign(item); this.item = item; item.newlyCreated = true; this.trigger(item); }.bind(this) }) }
The Component sees the flag and renders a "Notification Child Component"
var newlyCreated = this.state.item.newlyCreated === true; if (newlyCreated) { newlyCreated = <ItemCreatedNotification item={this.state.item} /> } else { newlyCreated = ''; } return ( <form onSubmit={this.createItem} className="form"> {newlyCreated}
Something needs to move the app to a new place based on this event. Should this be a) the Notification Child Component b) Parent Component c) The Store?
According to Colin Megill's talk on flux api patterns the api interaction should occur in the Action, but reflux doesn't really allow for that.
UPDATE 2
Component passes data to an Action called
createItemRequest
The Action has a preEmit hook that actually does the api call. The
createItemRequest
continues to the Store so that the store can change the model to reflect the state of sending which is then displayed in the component( maybe show a spinner ). The Action is also responsible for firing two other events depending on the api result.ItemActions.createItemRequest.preEmit = function (data) { $.ajax({ url: '/items', method: 'POST', data: data, success: function (item) { ItemActions.itemCreatedSuccess(item); }, error: function (error) { ItemActions.itemCreatedError(error); } }); }