Quick Start
Begin by installing AutoImmutable.
npm install --save auto-immutable
Creating an AutoImmutable instance
To create an AutoImmutable instance, simply instantiate the AutoImmutable class.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.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
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