GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

Property Path

What is a Property Path?

A property path is a dot-notation string leading to a specific property within an object.
Auto Immutable JS recognizes any property path abiding by the Lodash object path string specifications.
Auto Immutable JS will, in addition, resolve any such property paths containing negative integer indexes.

Note:
Negative integer [-N] in a property path indicates the nth last array index: resolved at runtime by counting abs(-N) steps backward from array length.

Ex. Given the following object:

1 2 3 4 5 6 7 8 { a: { c: { e: 5, f: [ 0, 2, 4 ] } } }
The property path a.c.e accesses the e=5 property.
Either of the property paths a.c.f.1, a.c.f.-2, a.c.f[1] and a.c.f[-2] is a valid property path to access the [1]=2 property.
A special property path, @@GLOBAL, may be used to access the AutoImmutable data as a whole.

What is the @@GLOBAL keyword?

@@GLOBAL is a property path which can be used to obtain a snapshot of the entire AutoImmutable data held within the AutoImmutable instance.

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 import AutoImmutable from 'auto-immutable'; const protectedData = { a: 1, b: 2, c: 3, d: { e: 5, f: [ 6, { x: 7, y: 8, z: 9 } ] } }; const aImmutable = new AutoImmutable( protectedData ); const consumer = aImmutable.connect(); consumer.get( '@@GLOBAL', 'd', 'd.f[1]' ); // returns // { // '@@GLOBAL': protectedData, // d: protectedData.d, // 'd.f[1]': protectedData.d.f[1] // };