clearNode
clearNode(unit, config?: {deep?: boolean}): void
Method for destroying stores, events, effects, subscriptions and domains
Arguments
unit
(Store/Event/Effect/Domain/Scope): 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: 0
inc()
// => inc called
// => store state: 1
clearNode($store)
inc()
// => inc called
Example 2 (with deep)
import {createStore, 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: 0
trigger()
// => trigger called
// => inc called
// => store state: 1
clearNode(trigger, {deep: true})
trigger()
// no reaction
inc()
// no reaction!
// all units, which depend on trigger, are erased
// including inc and store, because it depends on inc