MCPcopy
hub / github.com/nanostores/nanostores / MapStore

Interface MapStore

map/index.d.ts:46–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 : AllKeys<StoreValue<SomeStore>>
45
46export interface MapStore<
47 Value extends object = any
48> extends WritableAtom<Value> {
49 /**
50 * Subscribe to store changes.
51 *
52 * In contrast with {@link Store#subscribe} it do not call listener
53 * immediately.
54 *
55 * @param listener Callback with store value and old value.
56 * @param changedKey Key that was changed. Will present only if `setKey`
57 * has been used to change a store. It is `undefined` when
58 * changes were coalesced inside `batch`.
59 * @returns Function to remove listener.
60 */
61 listen(
62 listener: (
63 value: ReadonlyIfObject<Value>,
64 oldValue: ReadonlyIfObject<Value>,
65 changedKey: AllKeys<Value>
66 ) => void
67 ): () => void
68
69 /**
70 * Low-level method to notify listeners about changes in the store.
71 *
72 * Can cause unexpected behaviour when combined with frontend frameworks
73 * that perform equality checks for values, such as React.
74 */
75 notify(oldValue?: ReadonlyIfObject<Value>, changedKey?: AllKeys<Value>): void
76
77 /**
78 * Change store value.
79 *
80 * ```js
81 * $settings.set({ theme: 'dark' })
82 * ```
83 *
84 * Operation is atomic, subscribers will be notified once with the new value.
85 * `changedKey` will be undefined
86 *
87 * @param newValue New store value.
88 */
89 set(newValue: Value): void
90
91 /**
92 * Change key in store value.
93 *
94 * ```js
95 * $settings.setKey('theme', 'dark')
96 * ```
97 *
98 * To delete key set `undefined`.
99 *
100 * ```js
101 * $settings.setKey('theme', undefined)
102 * ```
103 *

Callers 34

index.test.tsFile · 0.65
index.test.tsFile · 0.65
index.test.tsFile · 0.65
errors.tsFile · 0.65
index.test.tsFile · 0.65
computedStoreFunction · 0.65
listenKeysFunction · 0.65
benchmark.jsFile · 0.65
deepMapFunction · 0.65
mapFunction · 0.65
index.test.tsFile · 0.65
index.test.tsFile · 0.65

Calls

no outgoing calls

Tested by

no test coverage detected