Mobx Understanding and Doubt summary __react

Source: Internet
Author: User

1. For the store understanding:

Http://cn.mobx.js.org/best/store.html

In complex projects, you can consider introducing Rootstore and provider to manage all the store;

The UI store can be used to do some global related processing, such as loading, screen size changes, and theme settings.

2. Based on the flexibility of coding, it is more convenient to modify the properties without adding use strict.

3. Class internal state can be completely replaced with this.xxx, in front plus @observerable, very convenient, class itself with @observer decoration. That is, this class is an observer, and it also observes the attributes within this class, such as the Watchon here:

@ observable Watchon = false; The initialization of internal properties is also simple: watch = new Watchstore ();

This allows you to get out of bondage and write the purest code (note the lifecycle). )

4. Questions TODO:

Componentwillreact ... In RN, if it works?


Action.bound something.


Atom what scenario to use.

5. Use of reaction:

Http://cn.mobx.js.org/refguide/reaction.html

  This.savehandler = reaction (
            ///observe anything used in JSON:
            () => This.asjson,
            //How AutoSave is True, send JSON to the server
            (JSON) => {
                if (this.autosave) {
                    This.store.transportLayer.saveTodo (JSON);
                }
            }
        );

The second method runs when and only if This.asjson returns a new value, and the value returned by This.asjson is the parameter JSON for the second method.

Its usage needs to be realized in practice.

6. Use of Autorun and its comparison with reaction

Constructor () {
Mobx.autorun (() => Console.log (This.report));
}

Autorun I understand is similar to a trigger in which all observable objects that are used will trigger its operation once it has changed. Reaction has something in common with it, but based on a change in the value of an expression and then triggers an action based on that value, it should be noted that the latter action will not be triggered by other observable objects it uses, which is different from the autorun.

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.