src/appstate.js
function getStateMutatorsAndAccessors (state, action, isAsync) {
  var mutators = [
    'apply',
    'concat',
    'deepMerge',
    'push',
    'merge',
    'unset',
    'set',
    'splice',
    'unshift'
  ];

  var accessors = [
    'get',
    'exists'
  ];

  var methods = [];

  if (isAsync) {
    methods = methods.concat(accessors);
  } else {
    methods = methods.concat(mutators);
    methods = methods.concat(accessors);
  }

  return methods.reduce((stateMethods, methodName) => {
    var method = state[methodName].bind(state);

    stateMethods[methodName] = (...args) => {
      var path = [];
      var firstArg = args[0];

      if (Array.isArray(firstArg)) {
        path = args.shift();
      } else if (typeof firstArg === 'string') {
        path = [args.shift()];
      }

      if (args.length === 0) {
        return method.apply(null, [path.slice()]);
      }

      action.mutations.push({
        name: methodName,
        path: path.slice(),
        args: args
      });

      return method.apply(null, [path.slice()].concat(args));
    };

    return stateMethods;
  }, Object.create(null));
}
function getStateMutatorsAndAccessors (state, action, isAsync) {
  var mutators = [
    'apply',
    'concat',
    'deepMerge',
    'push',
    'merge',
    'unset',
    'set',
    'splice',
    'unshift'
  ];

  var accessors = [
    'get',
    'exists'
  ];

  var methods = [];

  if (isAsync) {
    methods = methods.concat(accessors);
  } else {
    methods = methods.concat(mutators);
    methods = methods.concat(accessors);
  }

  return methods.reduce((stateMethods, methodName) => {
    var method = state[methodName].bind(state);

    stateMethods[methodName] = (...args) => {
      var path = [];
      var firstArg = args[0];

      if (Array.isArray(firstArg)) {
        path = args.shift();
      } else if (typeof firstArg === 'string') {
        path = [args.shift()];
      }

      if (args.length === 0) {
        return method.apply(null, [path.slice()]);
      }

      action.mutations.push({
        name: methodName,
        path: path.slice(),
        args: args
      });

      return method.apply(null, [path.slice()].concat(args));
    };

    return stateMethods;
  }, Object.create(null));
}
function getStateMutatorsAndAccessors ( state , action , isAsync ) { var mutators = [ 'apply' , 'concat' , 'deepMerge' , 'push' , 'merge' , 'unset' , 'set' , 'splice' , 'unshift' ] ; var accessors = [ 'get' , 'exists' ] ; var methods = [ ] ; if ( isAsync ) { methods = methods . concat ( accessors ) ; } else { methods = methods . concat ( mutators ) ; methods = methods . concat ( accessors ) ; } return methods . reduce ( ( stateMethods , methodName ) => { var method = state [ methodName ] . bind ( state ) ; stateMethods [ methodName ] = ( ... args ) => { var path = [ ] ; var firstArg = args [ 0 ] ; if ( Array . isArray ( firstArg ) ) { path = args . shift ( ) ; } else if ( typeof firstArg === 'string' ) { path = [ args . shift ( ) ] ; } if ( args . length === 0 ) { return method . apply ( null , [ path . slice ( ) ] ) ; } action . mutations . push ( { name : methodName , path : path . slice ( ) , args : args } ) ; return method . apply ( null , [ path . slice ( ) ] . concat ( args ) ) ; } ; return stateMethods ; } , Object . create ( null ) ) ; }
Get state mutators and accessors
Each mutation will save in action descriptor.
This method allow add ability
to gather information about call every function.
@param {Object} state
@param {Object} action
@param {Boolean} isAsync
@return {Object}
Get state mutators and accessors Each mutation will save in action descriptor . This method allow add ability to gather information about call every function .