GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

@@REPLACE Tag Usage

Signature:
{ '@@REPLACE': <any> }

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 import AutoImmutable, { Tag } from 'auto-immutable'; const protectedDatae = { a: { b: [ { x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 } ] }, j: 10 }; const aImmutable = new AutoImmutable( protectedData ); const consumer = aImmutable.connect(); /* rewrites aImmutable data to { a: 'Demo', j: 17 } */ consumer.set({ [ Tag.REPLACE ]: { a: 'Demo', j: 17 } }); /* rewrites aImmutable data.a to { message: 'Testing...' } */ consumer.set({ a: { [ Tag.REPLACE ]: { message: 'Testing...' } } }); // rewrites aImmutable data.a.b[1] to { x: 97, y: 98, z: 99 }; // leaving aImmutable data.a.b = [ // { x: 7, y: 8, z: 9 }, // { x: 97, y: 98, z: 99 } // ] consumer.set({ a: { b: [ aImmutable data.a.b[ 0 ], { [ Tag.REPLACE ]: { x: 97, y: 98, z: 99 } } ] } }); // rewrites aImmutable data.a.b[1] to { x: 97, y: 98, z: 99 }; // leaving aImmutable data.a.b = [ // { x: 7, y: 8, z: 9 }, // { x: 97, y: 98, z: 99 } // ] // uses indexing (RECOMMENDED) consumer.set({ a: { b: { 1: { [ Tag.REPLACE ]: { x: 97, y: 98, z: 99 } } } } });