import { clearNode } from "effector";

Method for destroying stores, events, effects, subscriptions, and domains.

Methods

clearNode(unit, config?)

Formulae

clearNode(unit, config?: {deep?: boolean}): void

Arguments

  1. unit (Store/Event/Effect/Domain/Scope): unit to be erased.
  2. config: {} (optional): config object.
    • deep?: boolean (optional): erase node and all of its computed values.

Returns

void

Examples

Simple

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

Try it

Deep clear

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

Try it

Contributors