store.setState
@@CLEAR Tag Usage
Sample: store.setState({ stateKey0: '@@CLEAR' });
Sample 2:
store.setState({ stateKey0: { '@@CLEAR': <any> // the value has no effect - removes `state.stateKey0` all the same. } });
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
import { CLEAR_TAG } from '@webkrafters/react-observable-context'; // CLEAR_TAG = "@@CLEAR"
const state = {
a: { b: [{ x: 7, y: 8, z: 9 }, { x: 17, y: 18, z: 19 }] },
j: 10
};
/* empties the state; sets state = {} */
store.setState( CLEAR_TAG ) // or store.setState({ [ CLEAR_TAG ]: <anything> })
/* empties the value at state.a.b; sets state.a.b = [] */
store.setState({ a: { b: CLEAR_TAG } }) // or store.setState({ a: { b: { [ CLEAR_TAG ]: <anything> } } })
/* empties the value at state.a.j; sets state.a.j = null */
store.setState({ a: { j: CLEAR_TAG } }) // or store.setState({ a: { j: { [ CLEAR_TAG ]: <anything> } } })
/* empties the value at state.a.b[ 0 ]; sets state.a.b = [{}] */
store.setState({ a: { b: [ CLEAR_TAG ] } }) // or store.setState({ a: { b: [ { [ CLEAR_TAG ]: <anything> } ] } })
/* empties the value at state.a.b[0]; sets state.a.b = [{}, state.a.b[1]] */
store.setState({ a: { b: [ CLEAR_TAG, state.a.b[1] ] } }) // or store.setState({ a: { b: [ { [ CLEAR_TAG ]: <anything> }, state.a.b[1] ] } })
/* empties the value at state.a.b[0]; sets state.a.b = [{}, a.b[1]] using indexing (RECOMMENDED) */
store.setState({ a: { b: { 0: CLEAR_TAG } } }) // or store.setState({ a: { b: { 0: { [ CLEAR_TAG ]: <anything> } } } })