Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1022 Bytes

README.md

File metadata and controls

58 lines (40 loc) · 1022 Bytes

shift(path, [n]) ⇒ object

Removes an element (or number of elements) from 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)
  • [n] number = 1 - number of items to remove

Description

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

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

const updated = reducer(state, ACTIONS.shift('a.b'));

// or

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

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

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

We can also pass number of items to remove as a 2nd argument:

const updated = reducer(state, ACTIONS.shift('a.b', 2));

Then result will be:

{
    a: {
        b: [ 3 ]
    }
}