I'm trying to understand Flux and Reactjs.
Consider a following, very simple scenario:
You have a form with few inputs. When user submits form,
ActionCreator.publishAnnouncement(this.state.announcement);
is called inside my form component. This is how the publishAnnouncement method looks like:
var publishAnnouncement = function (announcement) {
AnnouncementAPI.publishAnnouncement(
announcement,
successCallback,
failureCallback
)
};
AnnouncementAPI is just a wrapper upon an AJAX http POST call. It takes two callbacks - on success and on failure.
And now: I need to show a notification/toast on the screen - indicating success or failure. How would you do that in a Flux way?
I was thinking about creating Notification component and rendering it inside my form. Like the following:
<Notification title={this.state.notification.title} message={this.state.notification.title} visible={this.state.notification.visibility} // ?? onTimeExceeded ?? />
But how do I handle those callbacks? Should I create NotificationStore which listens for ANNOUNCEMENT_PUBLISHING_SUCCEEDED and ANNOUNCEMENT_PUBLISHING_FAILED events? In reaction to those events, store emits CHANGE event and thus my Notification updates.
But even if I do that, how should I instruct my Notification to show/hide? Or worse, to show up and hide after 2 seconds?
I've seen few components on GitHub and each of them uses refs etc, which I personally don't like.
To sum up: How would you implement this? Or maybe such project exists? If so, where can I find it?
refs
are the recommended way of implementing this. Sorry, your personality need to change ;-) – Begorra