insert(path, ...value) ⇒ object

Inserts elements to the specified position 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)
  • ...value any - values to be inserted

Description

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

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

const updated = reducer(state, ACTIONS.insert('a.b.1', 3, 4));

// or

const updated = reducer(state, ACTIONS.insert([ 'a', 'b', 'b1' ], 3, 4));

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

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

results matching ""

    No results matching ""