disposeStore
Disposes a root store created with createStore. Triggers the full disposal lifecycle: disposes reactions, recursively disposes all child stores, and calls onDispose callbacks.
Signature
function disposeStore<SD extends StoreDef>(store: Store<SD>): boolean;Parameters
| Parameter | Type | Description |
|---|---|---|
store |
Store<SD> |
The root store to dispose |
Returns
boolean — true if the store was successfully disposed, false if it was not a root store or was already disposed.
Example
import { createStore, disposeStore } from "@asimojs/mom";import { Counter } from "./counter/store";
const store = createStore(Counter, { value: 0 });
// ... use the store ...
disposeStore(store);// store.$state is now "DISPOSED"In React with cleanup
import { useEffect, useState } from "react";import { createStore, disposeStore } from "@asimojs/mom";
function App() { const [store] = useState(() => createStore(Counter));
useEffect(() => { return () => { disposeStore(store); }; }, [store]);
return <CounterView store={store} />;}Behavior
- Disposes all MobX reactions (autorun, reaction) registered on the store
- Recursively disposes all child stores (depth-first)
- Calls the store’s
onDisposecallback (if any) - Transitions
$statethroughDISPOSING→DISPOSED - Sets
$readytofalse - Resolves the
$disposeCompletepromise
Notes
- Only works on root stores created with
createStore. For child stores, usestore.unmount(). - Disposal may be async if
onDisposereturns a promise. Useawait store.$disposeCompleteto wait. - After disposal, model data can still be read but the store is no longer functional.