Playing with React and Flux
Let’s simplify that a bit. Reactive means that if any data is updated, then any component displaying that data in your UI is automatically updated.
That is React in a very simplified nutshell. If you’re a curious Developer, then you can head over to facebook.github.io/react to get started with React.
However, before you go we should point out that React has a problem: it only gives you the UI elements. It doesn’t give you the things you need to retrieve and do operations on data.
This is where Flux comes in. Now Flux is not something you can download. This a set of guidelines for an architecture that solves the React’s problem and simplifies the process of developing web apps.
To implement the Flux architecture you will need to do the following:
- Have a data store that contains data. As an example: Hasitha referred to database table being a data store for blog posts in a blog.
- The store has functions related to that specific store. Some examples of such functions are: to create blog posts, delete blog posts and edit blog posts.
- These functions are executed by the components with actions.
- Once data has been updated in the store, a change signal is emitted by the store which components listens to and updates their data accordingly.
- All this is handled by a single dispatcher which collects actions and sends it to the store.
Nadeesha opened his presentation with a trend called Data immutability. This is where data doesn’t change its state over time. An example being rather than updating an array with a new element, you clone the array, add the new element and destroy the old array.
The third trend Nadeesha touched on is Functional Reactive Programming. Here we don’t tell the computer what to do step by step. instead, the very simple idea behind Functional Reactive Programming is that we only tell the computer what to do with only the basic steps.
Assume you don’t know the future of your application. Assume your product manager will lie to you. Always use libraries. – Nadeesha Cabral