Read vuex light source

Minimalist version vuex Code

KVuex {class 
    constructor (Options) { 
        the this .STATE = options.state
         the this .mutations = options.mutations
         the this .actions = options.actions
         // responsive notification mechanism itself borrowed vue 
        // dependent state will need to collect Dep in 
        the this ._vm = new new KVUE ({ 
            Data: { 
                $ State: the this .STATE 
            } 
        }) 
    } 

    the commit (type, payload, _Options) { 
        const entry = the this .mutations [type] 
        entry.forEach (Handler =>handler(payload))
    }

    dispatch (type, payload) {
        const entry = this.actions[type]

        return entry(payload)
    }
}

      After the constructor constructor accepts parameters options, the options parameter passed in, preserved as a member property. vuex vue is dependent, to borrow vue responsive notification mechanism itself, declare a constructor in vue example, the state where the vuex assigned to Data instance, responsive to achieve dynamic changes.

    We did submit data to change behavior, what is it? There are three parameters commit type payload _options, we removed the corresponding function type from mutations in, its specific operation (execution function parameters passed)

    Dispatch and commit, accepts two parameters type payload, type function corresponding to the actions taken in, its specific operation (execution function parameters passed)

Guess you like

Origin www.cnblogs.com/superlizhao/p/10985975.html