Method for destroy stores, events, effects, subscriptions and domains
clearNode(unit, config?: {deep?: boolean}): void
Arguments
unit
(Store/Event/Effect/Domain): unit to be erasedconfig: ({deep?: boolean})
(optional): config objectdeep: boolean
(optional): erase node and all of its computed values
Returns
void
Example 1
import {createStore, createEvent, clearNode} from 'effector'
const inc = createEvent()const store = createStore(0).on(inc, x => x + 1)inc.watch(() => console.log('inc called'))store.watch(x => console.log('store state: ', x))// => store state: 0inc()// => inc called// => store state: 1clearNode(store)inc()// => inc called
Example 2 (with deep)
import {createStore, createStoreObject, createEvent, clearNode} from 'effector'
const inc = createEvent()const trigger = inc.prepend(() => {})const store = createStore(0).on(inc, x => x + 1)trigger.watch(() => console.log('trigger called'))inc.watch(() => console.log('inc called'))store.watch(x => console.log('store state: ', x))// => store state: 0trigger()// => trigger called// => inc called// => store state: 1clearNode(trigger, {deep: true})trigger()// no reactioninc()// no reaction!// all units, which depends on trigger, are erased// including inc and store, because it depends on inc