nanoeffects 0.2.0 → 0.2.1
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 +1 -1
- package/dist/notrace/redux.d.ts +1 -27
- package/dist/notrace/redux.js +1 -1
- package/dist/redux.d.ts +1 -27
- package/dist/redux.js +1 -1
- package/docs/stores.md +0 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ ESM only, no dependencies, types included.
|
|
|
65
65
|
| `nanoeffects/policies` | `latest`, `leading`, `debounce`, `throttle`, `queue` |
|
|
66
66
|
| `nanoeffects/effects` | `retry`, `timeout`, `poll`, `delay`, `take`, `all`, `allSettled`, `race` |
|
|
67
67
|
| `nanoeffects/actions` | `createAction`, `createCommand`, `createJob`, `createModule`, `modulePlugin` |
|
|
68
|
-
| `nanoeffects/redux` | `createEffectsMiddleware
|
|
68
|
+
| `nanoeffects/redux` | `createEffectsMiddleware` |
|
|
69
69
|
| `nanoeffects/observable` | `createObserve`: an event as an Observable (RxJS) |
|
|
70
70
|
| `nanoeffects/dev` | `devPlugin`: warnings about listeners that pile up and messages about modules; a no-op in production |
|
|
71
71
|
| `nanoeffects/trace` | `createTracer` and the loggers |
|
package/dist/notrace/redux.d.ts
CHANGED
|
@@ -9,32 +9,6 @@ type NanoeffectsMiddlewareOptions = {
|
|
|
9
9
|
/** Return `false` for the actions that the bus should not get. Default: all of them. */
|
|
10
10
|
filter?: (action: ReduxAction) => boolean;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* A Redux middleware that sends every action to the bus, after the reducers
|
|
14
|
-
* have handled it, so a handler that reads the store sees the new state. It
|
|
15
|
-
* does not depend on Redux: it only has the shape of a middleware. Values that
|
|
16
|
-
* are not plain actions (the functions of redux-thunk) go through untouched.
|
|
17
|
-
*
|
|
18
|
-
* The other way needs no adapter: give the store to the tasks with
|
|
19
|
-
* `createBus({ context: { store } })` and dispatch from a handler.
|
|
20
|
-
*
|
|
21
|
-
* Take care of loops: a handler must not dispatch the action it handles.
|
|
22
|
-
* Errors of handlers reach the caller of `dispatch`, as for `bus.emit`; set
|
|
23
|
-
* `onError` on the bus to isolate them.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const store = configureStore({
|
|
28
|
-
* reducer,
|
|
29
|
-
* middleware: (getDefault) => getDefault().concat(nanoeffectsMiddleware(bus)),
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* bus.on(userRequested, latest(async (id, { store, signal }) => {
|
|
33
|
-
* store.dispatch(userLoaded(await fetchUser(id, { signal })));
|
|
34
|
-
* }));
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare const nanoeffectsMiddleware: <E extends EventMap>(bus: Bus<E>, options?: NanoeffectsMiddlewareOptions) => () => (next: (action: unknown) => unknown) => (action: unknown) => unknown;
|
|
38
12
|
//#endregion
|
|
39
13
|
//#region src/store/redux/effects.d.ts
|
|
40
14
|
/** What Redux gives a middleware: the parts of the store that it may use. */
|
|
@@ -89,4 +63,4 @@ export declare const createEffectsMiddleware: <E extends EventMap = EventMap>(op
|
|
|
89
63
|
middleware: (storeApi: ReduxStoreApi) => (next: (action: unknown) => unknown) => (action: unknown) => unknown;
|
|
90
64
|
};
|
|
91
65
|
//#endregion
|
|
92
|
-
export type { EffectsMiddlewareOptions,
|
|
66
|
+
export type { EffectsMiddlewareOptions, ReduxStoreApi };
|
package/dist/notrace/redux.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e}from"./context-yAWj0BFZ.js";import{t}from"./bus-Dx0l9X6h.js";const n=e=>typeof e==`object`&&!!e&&`type`in e,r=(e,t={})=>{let r=e.emit;return()=>e=>i=>{let a=e(i);return n(i)&&(t.filter?.(i)??!0)&&r(i),a}},i=(n={})=>{let{filter:i,context:a,onError:o,...s}=n,c,l=/* @__PURE__ */ new WeakMap,u=e=>({...a,store:c&&{getState:c.getState,dispatch:t=>{typeof t==`object`&&t&&l.set(t,e.type);let n=t;return c?.dispatch(n)}}}),d=t({...s,onError:o??((t,{type:n})=>{e(`handler of "${n}" failed`,t)}),context:u}),f=r(d,{filter:e=>l.get(e)!==e.type&&(i?.(e)??!0)});return{bus:d,middleware:e=>(c=e,f())}};export{i as createEffectsMiddleware
|
|
1
|
+
import{c as e}from"./context-yAWj0BFZ.js";import{t}from"./bus-Dx0l9X6h.js";const n=e=>typeof e==`object`&&!!e&&`type`in e,r=(e,t={})=>{let r=e.emit;return()=>e=>i=>{let a=e(i);return n(i)&&(t.filter?.(i)??!0)&&r(i),a}},i=(n={})=>{let{filter:i,context:a,onError:o,...s}=n,c,l=/* @__PURE__ */ new WeakMap,u=e=>({...a,store:c&&{getState:c.getState,dispatch:t=>{typeof t==`object`&&t&&l.set(t,e.type);let n=t;return c?.dispatch(n)}}}),d=t({...s,onError:o??((t,{type:n})=>{e(`handler of "${n}" failed`,t)}),context:u}),f=r(d,{filter:e=>l.get(e)!==e.type&&(i?.(e)??!0)});return{bus:d,middleware:e=>(c=e,f())}};export{i as createEffectsMiddleware};
|
package/dist/redux.d.ts
CHANGED
|
@@ -9,32 +9,6 @@ type NanoeffectsMiddlewareOptions = {
|
|
|
9
9
|
/** Return `false` for the actions that the bus should not get. Default: all of them. */
|
|
10
10
|
filter?: (action: ReduxAction) => boolean;
|
|
11
11
|
};
|
|
12
|
-
/**
|
|
13
|
-
* A Redux middleware that sends every action to the bus, after the reducers
|
|
14
|
-
* have handled it, so a handler that reads the store sees the new state. It
|
|
15
|
-
* does not depend on Redux: it only has the shape of a middleware. Values that
|
|
16
|
-
* are not plain actions (the functions of redux-thunk) go through untouched.
|
|
17
|
-
*
|
|
18
|
-
* The other way needs no adapter: give the store to the tasks with
|
|
19
|
-
* `createBus({ context: { store } })` and dispatch from a handler.
|
|
20
|
-
*
|
|
21
|
-
* Take care of loops: a handler must not dispatch the action it handles.
|
|
22
|
-
* Errors of handlers reach the caller of `dispatch`, as for `bus.emit`; set
|
|
23
|
-
* `onError` on the bus to isolate them.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* const store = configureStore({
|
|
28
|
-
* reducer,
|
|
29
|
-
* middleware: (getDefault) => getDefault().concat(nanoeffectsMiddleware(bus)),
|
|
30
|
-
* });
|
|
31
|
-
*
|
|
32
|
-
* bus.on(userRequested, latest(async (id, { store, signal }) => {
|
|
33
|
-
* store.dispatch(userLoaded(await fetchUser(id, { signal })));
|
|
34
|
-
* }));
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare const nanoeffectsMiddleware: <E extends EventMap>(bus: Bus<E>, options?: NanoeffectsMiddlewareOptions) => () => (next: (action: unknown) => unknown) => (action: unknown) => unknown;
|
|
38
12
|
//#endregion
|
|
39
13
|
//#region src/store/redux/effects.d.ts
|
|
40
14
|
/** What Redux gives a middleware: the parts of the store that it may use. */
|
|
@@ -89,4 +63,4 @@ export declare const createEffectsMiddleware: <E extends EventMap = EventMap>(op
|
|
|
89
63
|
middleware: (storeApi: ReduxStoreApi) => (next: (action: unknown) => unknown) => (action: unknown) => unknown;
|
|
90
64
|
};
|
|
91
65
|
//#endregion
|
|
92
|
-
export type { EffectsMiddlewareOptions,
|
|
66
|
+
export type { EffectsMiddlewareOptions, ReduxStoreApi };
|
package/dist/redux.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./onAbort-BgMfspK4.js";import{t}from"./bus-CRnlwmQ4.js";const n=e=>typeof e==`object`&&!!e&&`type`in e,r=(e,t={})=>{let r=e.emit;return()=>e=>i=>{let a=e(i);return n(i)&&(t.filter?.(i)??!0)&&r(i),a}},i=(n={})=>{let{filter:i,context:a,onError:o,...s}=n,c,l=/* @__PURE__ */ new WeakMap,u=e=>({...a,store:c&&{getState:c.getState,dispatch:t=>{typeof t==`object`&&t&&l.set(t,e.type);let n=t;return c?.dispatch(n)}}}),d=t({...s,onError:o??((t,{type:n})=>{e(`handler of "${n}" failed`,t)}),context:u}),f=r(d,{filter:e=>l.get(e)!==e.type&&(i?.(e)??!0)});return{bus:d,middleware:e=>(c=e,f())}};export{i as createEffectsMiddleware
|
|
1
|
+
import{n as e}from"./onAbort-BgMfspK4.js";import{t}from"./bus-CRnlwmQ4.js";const n=e=>typeof e==`object`&&!!e&&`type`in e,r=(e,t={})=>{let r=e.emit;return()=>e=>i=>{let a=e(i);return n(i)&&(t.filter?.(i)??!0)&&r(i),a}},i=(n={})=>{let{filter:i,context:a,onError:o,...s}=n,c,l=/* @__PURE__ */ new WeakMap,u=e=>({...a,store:c&&{getState:c.getState,dispatch:t=>{typeof t==`object`&&t&&l.set(t,e.type);let n=t;return c?.dispatch(n)}}}),d=t({...s,onError:o??((t,{type:n})=>{e(`handler of "${n}" failed`,t)}),context:u}),f=r(d,{filter:e=>l.get(e)!==e.type&&(i?.(e)??!0)});return{bus:d,middleware:e=>(c=e,f())}};export{i as createEffectsMiddleware};
|
package/docs/stores.md
CHANGED
|
@@ -27,8 +27,6 @@ It looks after what is easy to get wrong:
|
|
|
27
27
|
|
|
28
28
|
Options are those of `createBus` (except `context`, which adds fields next to `store`) and `filter`, which keeps the actions it rejects away from the bus. Values that are not plain actions (thunks) go through untouched. Nothing here depends on Redux.
|
|
29
29
|
|
|
30
|
-
To use your own bus, `nanoeffectsMiddleware(bus, { filter })` is the middleware alone: it sends actions to the bus after the reducers and nothing more. Give the store to the tasks yourself with `createBus({ context: { store } })`, or lazily, `context: { get store() { return store; } }` (typed with `WithContext`), since the store needs the middleware and the middleware needs the bus.
|
|
31
|
-
|
|
32
30
|
## Zustand, MobX and other stores
|
|
33
31
|
|
|
34
32
|
No adapter is needed: a store tells about its changes, and `bus.emit` is a call.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nanoeffects",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Typed event bus where every handler is a task with an AbortSignal, plus policies (latest, debounce, throttle, queue), effects (retry, timeout, poll) and tracing. About 1.2 kB gzip.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"event-bus",
|