GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM
Latest

channel.setState @@CLEAR Tag Usage

Note: The following is also wholly applicable to global store.setState

Sample: channel.setState({ stateKey0: '@@CLEAR' });

Sample 2:
channel.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/eagleeye'; // 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 = {} */ channel.setState( CLEAR_TAG ) // or channel.setState({ [ CLEAR_TAG ]: <anything> }) /* empties the value at state.a.b; sets state.a.b = [] */ channel.setState({ a: { b: CLEAR_TAG } }) // or channel.setState({ a: { b: { [ CLEAR_TAG ]: <anything> } } }) /* empties the value at state.a.j; sets state.a.j = null */ channel.setState({ a: { j: CLEAR_TAG } }) // or channel.setState({ a: { j: { [ CLEAR_TAG ]: <anything> } } }) /* empties the value at state.a.b[ 0 ]; sets state.a.b = [{}] */ channel.setState({ a: { b: [ CLEAR_TAG ] } }) // or channel.setState({ a: { b: [ { [ CLEAR_TAG ]: <anything> } ] } }) /* empties the value at state.a.b[0]; sets state.a.b = [{}, state.a.b[1]] */ channel.setState({ a: { b: [ CLEAR_TAG, state.a.b[1] ] } }) // or channel.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) */ channel.setState({ a: { b: { 0: CLEAR_TAG } } }) // or channel.setState({ a: { b: { 0: { [ CLEAR_TAG ]: <anything> } } } })