I am trying to understand Flux and Reactjs.
Consider the following, very simple scenario:
You have a form with multiple inputs. When a user submits a form,
ActionCreator.publishAnnouncement(this.state.announcement);
called inside my form component. Here's what the publishAnnouncement method looks like:
var publishAnnouncement = function (announcement) { AnnouncementAPI.publishAnnouncement( announcement, successCallback, failureCallback ) };
AnnouncementAPI is just a wrapper when calling AJAX http POST. It requires two callbacks - from success and from failure.
And now: I need to show a notification / toast on the screen - this indicates success or failure. How do you do this with Flux?
I was thinking about creating a Notification component and rendering it in my form. As below:
<Notification title={this.state.notification.title} message={this.state.notification.title} visible={this.state.notification.visibility}
But how do I handle these callbacks? Should I create a NotificationStore that listens for ANNOUNCEMENT_PUBLISHING_SUCCEEDED and ANNOUNCEMENT_PUBLISHING_FAILED events? In response to these events, the store emits a CHANGE event and thus my notification updates.
But even if I do, how should I indicate my notification to show / hide? Or worse, to show and hide after 2 seconds?
I saw several components on GitHub , and each of them uses links, etc., which I personally don’t like.
To summarize: How would you implement this? Or maybe such a project exists? If so, where can I find it?