GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

@@MOVE Tag Usage

Signature:
{
    '@@MOVE': [
        -/+fromIndex,
        -/+toIndex,
        +numItemsToMove? = 1
    ]
}

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 '@webkrafters/react-observable-context'; 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 '@@MOVE' command to a non-array property has no effect. */ consumer.set({ a: { [ Tag.MOVE ]: [ 0, 1 ] } }); // moves aImmutable data.a.b[0] into index 1; // leaving aImmutable data.a.b = [{ // x: 17, y: 18, z: 19 }, // { x: 7, y: 8, z: 9 } // ] consumer.set({ a: { b: { [ Tag.MOVE ]: [ 0, 1 ] // or [ -2, -1 ] with negative indexing } } }); // moves aImmutable data.q[4] - [7] into indexes 1 - 4; // leaving aImmutable data.q = [ 1, 5, 6, 7, 8, 2, 3, 4, 9 ] consumer.set({ a: { q: { [ Tag.MOVE ]: [ 4, 1, 4 ] // or [ -5, -8, 4 ] with negative indexing } } });