GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

Getting Started

Begin by installing AutoImmutable.
npm install --save auto-immutable

Creating an AutoImmutable instance

To create an AutoImmutable instance, simply instantiate the AutoImmutable class.
sample-instance.js
1 2 3 4 5 6 7 8 9 10 11 import AutoImmutable from 'auto-immutable'; export interface SampleValue { property?: { value: number; } }; const initValue : SampleValue = {}; // any object really! export const sample = new AutoImmutable( initValue );

Using the AutoImmutable instance

Once instantiated, the new instance can be exported and reused.
user1.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import { sample } from 'sample-instance'; const data = sample.connect(); console.log( data.get( 'property.value' ) ); // logs: undefined data.set({ property: { value: 44 } }); console.log( data.get( 'property.value' ) ); // logs: 44 data.disconnect(); // severs access to the sample AutoImmutable instance

Sharing the AutoImmutable instance

Once instantiated, all connections read and write to the same underlying AutoImmutable data.
user2.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import { sample } from 'sample-instance'; const data = sample.connect(); console.log( data.get( 'property.value' ) ); // logs: 44 data.set({ property: { value: 127 } }); console.log( data.get( 'property.value' ) ); // logs: 127 data.disconnect(); // severs access to the sample AutoImmutable instance