@@DELETE Tag Usage
Signature:{
'@@DELETE': [
...keysToRemove
]
};
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
import AutoImmutable, { Tag } from 'auto-immutable';
const protectedData = {
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();
// removes aImmutable data.a;
// sets aImmutable data = {j: 10}
consumer.set({ [ Tag.DELETE ]: [ 'a' ] });
// removes aImmutable data.a.b;
// sets aImmutable data.a = {}
consumer.set({ a: { [ Tag.DELETE ]: [ 'b' ] } });
// removes aImmutable data.a.b[0];
// leaving aImmutable data.a.b = [{ x: 17, y: 18, z: 19 }]
consumer.set({
a: {
b: {
[ Tag.DELETE ]: [ 0 ] // [ -2 ] with negative indexing
}
}
});
// removes `x` and `z` properties from aImmutable data.a.b[1];
// sets aImmutable data.a.b = [
// { x: 7, y: 8, z: 9 },
// {y: 18}
// ]
consumer.set({
a: {
b: [
aImmutable data.a.b[ 0 ],
{
[ Tag.DELETE ]: [ 'x', 'z' ]
}
]
}
});
// removes `x` and `z` properties from aImmutable data.a.b[1];
// sets aImmutable data.a.b = [
// { x: 7, y: 8, z: 9 },
// {y: 18}
// ]
// uses indexing (RECOMMENDED)
consumer.set({
a: {
b: {
1: {
[ Tag.DELETE ]: [ 'x', 'z' ]
}
}
}
});