Compare redux and reflux and write TinyFlux? -

Source: Internet
Author: User
After reading redux and reflux, I feel that redux is so complicated. I can understand it in an hour, but I am confused when I look at redux. It seems that flux should not send a message to the store at the view layer. The store modifies the data based on the message. After the data is modified, will it notify the modified view to set up a refresh state... Then I looked at the use of reflux (its source code is not easy to see, it still feels much more) and wrote a tinyFlux myself... Attached on the second floor .. Let's take a look .. After reading redux and reflux, I feel that redux is so complicated. I can understand it in an hour, but I am confused when I look at redux.

It seems that flux should not send a message to the store at the view layer. The store modifies the data based on the message. After the data is modified, will it notify the modified view to set up a refresh state...

Then I looked at the use of reflux (its source code is not easy to see, it still feels much more) and wrote a tinyFlux myself... Attached on the second floor .. Let's take a look .... It may be too naive... Thank you for your criticism... Reply: Thank you for your invitation. There are too many Flux-related wheels. Sorry.

Let's briefly talk about the differences between Reflux and Redux.

How can I understand Facebook's flux application architecture? -As mentioned in users' answers, many Flux-related frameworks on the market currently hide Dispatcher and encapsulate the binding details of Action Creator and Component, simply put, it is "Simplifying redundant code and operations in Flux 」.

Based on the implementation of the content mentioned above, Reflux also provides many features that developers like. For example, View listening Action is a convenient feature that violates the Flux concept but is indeed very convenient in practical applications.

Redux is not just "simplified Flux", but it redefined the functions, responsibilities, and implementation methods of each role in Flux. The biggest difference is that there is no Store concept (or the Store does not need to be defined by users), but the Reducer concept is added. Store will be automatically generated using the CER defined by us, using the redux. createStore method. In addition, Redux defines a middleware mechanism, which makes it easier for us to process business logic in Action.

To sum up, if you think Flux is using too much redundant code, TinyFlux you wrote is good and solves many of your problems; however, if you want to have more new features brought about by redux, or if you like and advocate immutable data structures, or if you want to be more advanced, so understanding and using redux is definitely your best choice.

PS. redux is really good. We have started to use it in the production environment. Redux core concepts Deep introduction to Redux http://www.w3ctech.com/topic/1561

// TinyFlux. jsfunction createStore (store,... args) {if (! Store) {throw new Error ('Please define store') ;}; if (typeof store. init = 'function') {store. init (args) ;}; if (typeof store. actions! = 'Function') {throw new Error ('actions should be a function that returns an object. All methods in the object must be written using an arrow expression and bound using this of an arrow expression. ');}; Store. actions = store. actions (); if (store. subscriber | store. emit) {throw new Error ('subscriber and emit' shouldn't exist) ;}; store. subscriber = []; store. emit = function (argument) {store. subscriber. forEach (component => component. reload () ;}; return store ;}function connect (store, def) {return {getInitialState: function () {var state ={}; for (var I in def) {try {state [I] = eval ('store. '+ def [I]);} catch (err) {console. log (err) ;}}; return state ;}, reload: function () {var state ={}; for (var I in def) {try {state [I] = eval ('store. '+ def [I]);} catch (err) {console. log (err) ;}}; this. setState (state) ;}, componentDidMount: function () {store. subscriber. push (this) ;}, componentWillUnmount: function () {store. subscriber. splice (store. subscriber. indexOf (this), 1) ;};} module. exports = {createStore: createStore, connect: connect}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.