pop(path, [n]) ⇒ object

Removes an element (or number of elements) from the end 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.pop('a.b'));

// or

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

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

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

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

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

Then result will be

{
    a: {
        b: [ 1 ]
    }
}

results matching ""

    No results matching ""