unshiftAll(path, values) ⇒ object

Adds list of elements to the beginning of array

Returns: object - action object
Params

  • path number | string | Array.<(string|number)> - path to be updated (array of items or dot-separated string can be provided)
  • values Array.<any> - values to be added

Description

This action is similar to unshift() but consumes array of items as 2nd argument:

import { ACTIONS, reducer } from 'general-reducer';

const state = {
    a: {
        b: [ 1 ]
    }
};

const updated = reducer(state, ACTIONS.unshiftAll('a.b', [ 2, 3 ]));

// or

const updated = reducer(state, ACTIONS.unshiftAll([ 'a', 'b' ], [ 2, 3 ]));

As a result we will receive new object with structure below:

{
    a: {
        b: [ 2, 3, 1 ]
    }
}

results matching ""

    No results matching ""