How to use several $ splices in one collection with reagent reactivation assistants

Everything:

I am new to React Immutability Helpers when I try to use $ splice, for example:

Doc $ splice :

{$ splice: an array of arrays} for each element of the call splice () array on the target with the parameters provided by the element.

var update = require('react-addons-update'); var collection = [1, 2, {a: [1,2,3,4,5,6]}]; var newCollection = update(collection, { 2: { a: { $splice: [ [1, 1, 33, 44], [3, 2, 55, 66], ] } } }); 

I thought that all operations in this $ splice array should be based on the original goal, take my code, for example:

[1, 1, 33, 44] will replace 2 with 33, 44

[3, 2, 55, 66] will replace 4, 5 with 55 66

therefore, the final failure should be [1, 33, 44, 3, 55, 66, 6]

But the actual result is [1, 33, 44, 55, 66, 5, 6], which seems to be that these two operations are based on the previous array of operation results.

So wondering how I can apply all operations to the original target?

thanks

+5
source share
1 answer

Not too sure about reagent reactivation recommendations, but in JS you usually use slice to keep the array to its original value. splice really modifies the original array, so any subsequent operation will be performed with the result of the previous one.

0
source

All Articles