GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

@@SPLICE Tag Usage

Signature:
{
    '@@SPLICE': [
        -/+fromIndex,
        deleteCount, // integer >= 0
        ...newInserts?
    ]
}

Example:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 import AutoImmutable, { Tag } from 'auto-immutable'; const protectedData = { a: { b: [ { x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 } ] }, j: 10, q: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }; const aImmutable = new AutoImmutable( protectedData ); const consumer = aImmutable.connect(); /* assigning a '@@SPLICE' command to a non-array property has no effect. */ consumer.set({ a: { [ Tag.SPLICE ]: [ 0, 1 ] } }); // removes aImmutable data.a.b[0]; // leaving aImmutable data.a.b = [ // { x: 17, y: 18, z: 19 } // ] consumer.set({ a: { b: { [ Tag.SPLICE ]: [ 0, 1 ] // or [ -2, -1 ] with negative indexing } } }); // replaces aImmutable data.q[4] - [7] with 2 items; // leaving aImmutable data.q = [ 1, 2, 3, 4, 33, 88, 9 ] consumer.set({ a: { q: { [ Tag.SPLICE ]: [ 4, 4, 33, 88 ] // or [ -5, 4, 33, 88 ] with negative indexing } } });