src/store.js
function makeLocalContext (store, namespace, path) {
  const noNamespace = namespace === ''

  const local = {
    dispatch: noNamespace ? store.dispatch : (_type, _payload, _options) => {
      const args = unifyObjectStyle(_type, _payload, _options)
      const { payload, options } = args
      let { type } = args

      if (!options || !options.root) {
        type = namespace + type
        if (process.env.NODE_ENV !== 'production' && !store._actions[type]) {
          console.error(`[vuex] unknown local action type: ${args.type}, global type: ${type}`)
          return
        }
      }

      return store.dispatch(type, payload)
    },

    commit: noNamespace ? store.commit : (_type, _payload, _options) => {
      const args = unifyObjectStyle(_type, _payload, _options)
      const { payload, options } = args
      let { type } = args

      if (!options || !options.root) {
        type = namespace + type
        if (process.env.NODE_ENV !== 'production' && !store._mutations[type]) {
          console.error(`[vuex] unknown local mutation type: ${args.type}, global type: ${type}`)
          return
        }
      }

      store.commit(type, payload, options)
    }
  }

  // getters and state object must be gotten lazily
  // because they will be changed by vm update
  Object.defineProperties(local, {
    getters: {
      get: noNamespace
        ? () => store.getters
        : () => makeLocalGetters(store, namespace)
    },
    state: {
      get: () => getNestedState(store.state, path)
    }
  })

  return local
}
function makeLocalContext (store, namespace, path) {
  const noNamespace = namespace === ''

  const local = {
    dispatch: noNamespace ? store.dispatch : (_type, _payload, _options) => {
      const args = unifyObjectStyle(_type, _payload, _options)
      const { payload, options } = args
      let { type } = args

      if (!options || !options.root) {
        type = namespace + type
        if (process.env.NODE_ENV !== 'production' && !store._actions[type]) {
          console.error(`[vuex] unknown local action type: ${args.type}, global type: ${type}`)
          return
        }
      }

      return store.dispatch(type, payload)
    },

    commit: noNamespace ? store.commit : (_type, _payload, _options) => {
      const args = unifyObjectStyle(_type, _payload, _options)
      const { payload, options } = args
      let { type } = args

      if (!options || !options.root) {
        type = namespace + type
        if (process.env.NODE_ENV !== 'production' && !store._mutations[type]) {
          console.error(`[vuex] unknown local mutation type: ${args.type}, global type: ${type}`)
          return
        }
      }

      store.commit(type, payload, options)
    }
  }

  // getters and state object must be gotten lazily
  // because they will be changed by vm update
  Object.defineProperties(local, {
    getters: {
      get: noNamespace
        ? () => store.getters
        : () => makeLocalGetters(store, namespace)
    },
    state: {
      get: () => getNestedState(store.state, path)
    }
  })

  return local
}
function makeLocalContext ( store , namespace , path ) { const noNamespace = namespace === '' const local = { dispatch : noNamespace ? store . dispatch : ( _type , _payload , _options ) => { const args = unifyObjectStyle ( _type , _payload , _options ) const { payload , options } = args let { type } = args if ( ! options || ! options . root ) { type = namespace + type if ( process . env . NODE_ENV !== 'production' && ! store . _actions [ type ] ) { console . error ( ` ${ args . type } ${ type } ` ) return } } return store . dispatch ( type , payload ) } , commit : noNamespace ? store . commit : ( _type , _payload , _options ) => { const args = unifyObjectStyle ( _type , _payload , _options ) const { payload , options } = args let { type } = args if ( ! options || ! options . root ) { type = namespace + type if ( process . env . NODE_ENV !== 'production' && ! store . _mutations [ type ] ) { console . error ( ` ${ args . type } ${ type } ` ) return } } store . commit ( type , payload , options ) } } // getters and state object must be gotten lazily // because they will be changed by vm update Object . defineProperties ( local , { getters : { get : noNamespace ? ( ) => store . getters : ( ) => makeLocalGetters ( store , namespace ) } , state : { get : ( ) => getNestedState ( store . state , path ) } } ) return local }
make localized dispatch, commit, getters and state
if there is no namespace, just use root ones
make localized dispatch commit getters and state if there is no namespace just use root ones