GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

Updating AutoImmutable Data

Any AutoImmutable instance communicates with its environment through its own Connection class (the consumer) instances.
The set(...) method of the Connection instance provides the means of updating AutoImmutable data.
Any attempt to update through any other means is a noop.
This set(...) method accepts 2 arguments - namely:
  1. changes: a single object payload or an array of object payloads containing data nodes to add and/or merge into the AutoImmutable instance data along with operations to perform at specific existing data nodes.
  2. onComplete: an optional callback function to be called at the completion of the update operation. This callback is invoked with the changes payload object.
It will create new property pathways into the AutoImmutable instance data for new properties found in changes payload object.

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 import AutoImmutable from 'auto-immutable'; const aImmutable = new AutoImmutable({ a: { b: 5, c: [ 6, { d: 7, e: 8, f: 9 } ] } }); const consumer = aImmutable.connect(); consumer.set({ p: 'some test data', a: { p: { t: true }, c: { 1: { e: 720 } 3: /w+/ } } }); // updates the AutoImmutable instance data to: // { // a: { // b: 5, // c: [ // 6, // { // d: 7, // e: 720, // f: 9 // }, // undefined, // /w+/ // ], // p: { // t: true // } // }, // p: 'some test data' }

More on the `changes` Argument Payload