@oxog/state 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,6 +31,15 @@ yarn add @oxog/state
31
31
  pnpm add @oxog/state
32
32
  ```
33
33
 
34
+ The main entry `@oxog/state` also exports the React hooks, so it imports
35
+ `react` (>= 18). Without React (Node.js, Vue, Svelte, plain DOM) import from
36
+ `@oxog/state/vanilla`: the same API without the hooks, and it never imports
37
+ `react`.
38
+
39
+ ```typescript
40
+ import { createStore, persist } from '@oxog/state/vanilla';
41
+ ```
42
+
34
43
  ## Quick Start
35
44
 
36
45
  ```tsx
@@ -129,6 +138,9 @@ Notes on subscriber semantics:
129
138
  - A listener added during a notification is first called for the next change.
130
139
  - `getState()` returns the live state object. Treat it as read-only: mutating
131
140
  it bypasses subscribers. Use `setState`, `merge` or the `immer` plugin.
141
+ - Using a destroyed store, registering a plugin name twice or a missing plugin
142
+ dependency throws a `StoreError` (an `Error` with a `code` from
143
+ `StoreErrorCode`, e.g. `StoreErrorCode.STORE_DESTROYED`).
132
144
 
133
145
  ### React Hooks
134
146
 
@@ -263,6 +275,7 @@ const store = combineSlices(userSlice, cartSlice);
263
275
  store.login('John', 'john@example.com');
264
276
  store.addItem('book');
265
277
  store.getState().name; // 'John'
278
+ store.getState().logout(); // slice actions are on the state too
266
279
 
267
280
  resetSlices(store, 'cart'); // resets only the cart slice
268
281
  ```
@@ -356,7 +369,8 @@ const store = createStore({ count: 0, temp: '' })
356
369
  Hydration ignores `__proto__` keys in stored data, corrupt stored data is
357
370
  reported through `onPersistError` (or `console.error`) instead of throwing,
358
371
  and write errors such as a full storage quota are reported the same way.
359
- Without `window` (SSR) the default storage does nothing.
372
+ Without `window` (SSR) the default storage does nothing. With `writeDebounce`,
373
+ a write that is still pending when the store is destroyed is saved right away.
360
374
 
361
375
  ### DevTools
362
376
 
@@ -393,8 +407,9 @@ if (hasHistory(store)) {
393
407
  ### Sync
394
408
 
395
409
  Synchronize state across browser tabs (BroadcastChannel). Every local change is
396
- sent to the other tabs; when the plugin is installed the current state is
397
- broadcast once. Action functions are not sent.
410
+ sent to the other tabs. A newly opened tab does not broadcast its initial
411
+ state; it asks the open tabs for theirs and takes the first reply (unless it
412
+ has changed its state in the meantime). Action functions are not sent.
398
413
 
399
414
  ```typescript
400
415
  import { createStore, sync } from '@oxog/state';