@ludekarts/minirdx 0.3.0 → 0.5.0-beta.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/dist/minirdx.index.cjs.js +1 -1
- package/dist/minirdx.index.es.js +81 -71
- package/dist/minirdx.react.cjs.js +1 -1
- package/dist/minirdx.react.es.js +14 -14
- package/dist/react.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=["on","state","actions"];function _(t){let{state:n,actions:a}=t;const r=[],s=new Map;E(n,(e,o)=>{if(b(e)){const{setter:u}=g(`state.${o}`),i=c=>{u(l(),c),y()};e._rdx_link_(i)}});const f=Object.fromEntries(Object.entries(a).map(([e,o])=>{if($.includes(e))throw new Error(`MiniRdxError: "${e}" is a reserved keyword`);if(typeof o!="function")throw new Error(`MiniRdxError: "${e}" should be a function`);return[e,(...u)=>new Promise((i,c)=>{p(e,w=>o(w,...u),i,c)})]}));function p(e,o,u,i){try{const c=o(l);S(c)?c.then(w=>d(w,e,u)).catch(i):d(c,e,u)}catch(c){i(c)}}function d(e,o,u){var i;n=e,r.length&&r.forEach(c=>c(n,o)),(i=s.get(o))==null||i.forEach(c=>c(n,o)),u(n)}function l(){return n}function y(){const e=x(n)?{...n}:Array.isArray(n)?[...n]:n;r.length&&r.forEach(o=>o(e,"link"))}function h(e,o){var u;if(typeof e=="function"&&o===void 0)return r.push(e),()=>{const i=r.indexOf(e);i>=0&&r.splice(i,1)};if(typeof e=="string"&&o)return s.has(e)||s.set(e,[]),(u=s.get(e))==null||u.push(o),()=>{const i=s.get(e);if(!i)return;const c=i.indexOf(o);c>=0&&i.splice(c,1)};throw new Error("MiniRdxError: Invalid arguments. Try: state.on(action: string, listener: ActionListener)")}return{state:l,actions:f,on:h}}function m(t,n){const{getter:a,setter:r}=g(t),s=f=>Array.isArray(f)?[...f]:x(f)?{...f}:f;return function(p,...d){const l=n(a(p()),...d);if(S(l))return Promise.resolve(l).then(h=>{const e=r(p(),h);return s(e)});const y=r(p(),l);return s(y)}}function g(t){if(/^state\.[\w\[\]\d\.]+$/.test(t))return{getter:new Function("state",`return ${t}`),setter:new Function("state","value",`{${t} = value; return state;}`)};throw new Error('MiniRDXError: Selector should be a string with dot notation starting with "state." e.g.: "state.user.cars[1].model" ')}function A(...t){return Object.freeze({_rdx_link_:n=>{const a=t.pop(),r=t,s=()=>{n(a(...r.map(f=>f.state())))};r.forEach(f=>f.on(()=>s())),s()}})}function S(t){return!!t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function"}function E(t,n,a=""){if(!(typeof t!="object"||t===null)){for(const r in t)if(O(t,r)){const s=t[r],f=/\d+/.test(r)?`[${r}]`:`.${r}`,p=a?`${a}${f}`:r;n(s,p),typeof s=="object"&&s!==null&&E(s,n,p)}}}function b(t){return t!==null&&typeof t=="object"&&O(t,"_rdx_link_")}function O(t,n){return Object.prototype.hasOwnProperty.call(t,n)}function x(t){return!!t&&typeof t!="symbol"&&typeof t!="string"&&typeof t!="number"&&typeof t!="boolean"&&typeof t!="function"&&!Array.isArray(t)}exports.createSelector=g;exports.createStore=_;exports.link=A;exports.selector=m;
|
package/dist/minirdx.index.es.js
CHANGED
|
@@ -1,83 +1,93 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
let { state:
|
|
1
|
+
const $ = ["on", "state", "actions"];
|
|
2
|
+
function A(t) {
|
|
3
|
+
let { state: e, actions: a } = t;
|
|
4
4
|
const r = [], s = /* @__PURE__ */ new Map();
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
const { setter:
|
|
8
|
-
|
|
5
|
+
x(e, (n, o) => {
|
|
6
|
+
if (_(n)) {
|
|
7
|
+
const { setter: u } = g(`state.${o}`), i = (c) => {
|
|
8
|
+
u(d(), c), l();
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
n._rdx_link_(i);
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
const
|
|
14
|
-
Object.entries(a).map(([
|
|
15
|
-
if (
|
|
16
|
-
throw new Error(`MiniRdxError: "${
|
|
13
|
+
const f = Object.fromEntries(
|
|
14
|
+
Object.entries(a).map(([n, o]) => {
|
|
15
|
+
if ($.includes(n))
|
|
16
|
+
throw new Error(`MiniRdxError: "${n}" is a reserved keyword`);
|
|
17
17
|
if (typeof o != "function")
|
|
18
|
-
throw new Error(`MiniRdxError: "${
|
|
18
|
+
throw new Error(`MiniRdxError: "${n}" should be a function`);
|
|
19
19
|
return [
|
|
20
|
-
|
|
21
|
-
(...
|
|
20
|
+
n,
|
|
21
|
+
(...u) => new Promise((i, c) => {
|
|
22
22
|
p(
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
i
|
|
23
|
+
n,
|
|
24
|
+
(w) => o(w, ...u),
|
|
25
|
+
i,
|
|
26
|
+
c
|
|
26
27
|
);
|
|
27
28
|
})
|
|
28
29
|
];
|
|
29
30
|
})
|
|
30
31
|
);
|
|
31
|
-
function p(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
32
|
+
function p(n, o, u, i) {
|
|
33
|
+
try {
|
|
34
|
+
const c = o(d);
|
|
35
|
+
E(c) ? c.then(
|
|
36
|
+
(w) => y(w, n, u)
|
|
37
|
+
).catch(i) : y(c, n, u);
|
|
38
|
+
} catch (c) {
|
|
39
|
+
i(c);
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
|
-
function
|
|
42
|
+
function y(n, o, u) {
|
|
38
43
|
var i;
|
|
39
|
-
|
|
44
|
+
e = n, r.length && r.forEach((c) => c(e, o)), (i = s.get(o)) == null || i.forEach((c) => c(e, o)), u(e);
|
|
40
45
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
46
|
+
function d() {
|
|
47
|
+
return e;
|
|
43
48
|
}
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
r.length && r.forEach((o) => o(
|
|
49
|
+
function l() {
|
|
50
|
+
const n = S(e) ? { ...e } : Array.isArray(e) ? [...e] : e;
|
|
51
|
+
r.length && r.forEach((o) => o(n, "link"));
|
|
47
52
|
}
|
|
48
|
-
function
|
|
49
|
-
var
|
|
50
|
-
if (typeof
|
|
51
|
-
return r.push(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
function h(n, o) {
|
|
54
|
+
var u;
|
|
55
|
+
if (typeof n == "function" && o === void 0)
|
|
56
|
+
return r.push(n), () => {
|
|
57
|
+
const i = r.indexOf(n);
|
|
58
|
+
i >= 0 && r.splice(i, 1);
|
|
59
|
+
};
|
|
60
|
+
if (typeof n == "string" && o)
|
|
61
|
+
return s.has(n) || s.set(n, []), (u = s.get(n)) == null || u.push(o), () => {
|
|
62
|
+
const i = s.get(n);
|
|
63
|
+
if (!i) return;
|
|
64
|
+
const c = i.indexOf(o);
|
|
65
|
+
c >= 0 && i.splice(c, 1);
|
|
56
66
|
};
|
|
57
67
|
throw new Error(
|
|
58
68
|
"MiniRdxError: Invalid arguments. Try: state.on(action: string, listener: ActionListener)"
|
|
59
69
|
);
|
|
60
70
|
}
|
|
61
71
|
return {
|
|
62
|
-
state:
|
|
63
|
-
actions:
|
|
64
|
-
on:
|
|
72
|
+
state: d,
|
|
73
|
+
actions: f,
|
|
74
|
+
on: h
|
|
65
75
|
};
|
|
66
76
|
}
|
|
67
|
-
function m(t,
|
|
68
|
-
const { getter: a, setter: r } =
|
|
69
|
-
return function(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
function m(t, e) {
|
|
78
|
+
const { getter: a, setter: r } = g(t), s = (f) => Array.isArray(f) ? [...f] : S(f) ? { ...f } : f;
|
|
79
|
+
return function(p, ...y) {
|
|
80
|
+
const d = e(a(p()), ...y);
|
|
81
|
+
if (E(d))
|
|
82
|
+
return Promise.resolve(d).then((h) => {
|
|
83
|
+
const n = r(p(), h);
|
|
84
|
+
return s(n);
|
|
85
|
+
});
|
|
86
|
+
const l = r(p(), d);
|
|
87
|
+
return s(l);
|
|
78
88
|
};
|
|
79
89
|
}
|
|
80
|
-
function
|
|
90
|
+
function g(t) {
|
|
81
91
|
if (/^state\.[\w\[\]\d\.]+$/.test(t))
|
|
82
92
|
return {
|
|
83
93
|
getter: new Function("state", `return ${t}`),
|
|
@@ -91,40 +101,40 @@ function d(t) {
|
|
|
91
101
|
'MiniRDXError: Selector should be a string with dot notation starting with "state." e.g.: "state.user.cars[1].model" '
|
|
92
102
|
);
|
|
93
103
|
}
|
|
94
|
-
function
|
|
104
|
+
function L(...t) {
|
|
95
105
|
return Object.freeze({
|
|
96
|
-
_rdx_link_: (
|
|
106
|
+
_rdx_link_: (e) => {
|
|
97
107
|
const a = t.pop(), r = t, s = () => {
|
|
98
|
-
|
|
108
|
+
e(a(...r.map((f) => f.state())));
|
|
99
109
|
};
|
|
100
|
-
r.forEach((
|
|
110
|
+
r.forEach((f) => f.on(() => s())), s();
|
|
101
111
|
}
|
|
102
112
|
});
|
|
103
113
|
}
|
|
104
|
-
function
|
|
114
|
+
function E(t) {
|
|
105
115
|
return !!t && (typeof t == "object" || typeof t == "function") && typeof t.then == "function";
|
|
106
116
|
}
|
|
107
|
-
function
|
|
108
|
-
return t.constructor.name === "AsyncFunction";
|
|
109
|
-
}
|
|
110
|
-
function w(t, n, a = "") {
|
|
117
|
+
function x(t, e, a = "") {
|
|
111
118
|
if (!(typeof t != "object" || t === null)) {
|
|
112
119
|
for (const r in t)
|
|
113
|
-
if (t
|
|
114
|
-
const s = t[r],
|
|
115
|
-
|
|
120
|
+
if (O(t, r)) {
|
|
121
|
+
const s = t[r], f = /\d+/.test(r) ? `[${r}]` : `.${r}`, p = a ? `${a}${f}` : r;
|
|
122
|
+
e(s, p), typeof s == "object" && s !== null && x(s, e, p);
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
|
-
function
|
|
120
|
-
return t !== null && typeof t == "object" && t
|
|
126
|
+
function _(t) {
|
|
127
|
+
return t !== null && typeof t == "object" && O(t, "_rdx_link_");
|
|
128
|
+
}
|
|
129
|
+
function O(t, e) {
|
|
130
|
+
return Object.prototype.hasOwnProperty.call(t, e);
|
|
121
131
|
}
|
|
122
|
-
function
|
|
132
|
+
function S(t) {
|
|
123
133
|
return !!t && typeof t != "symbol" && typeof t != "string" && typeof t != "number" && typeof t != "boolean" && typeof t != "function" && !Array.isArray(t);
|
|
124
134
|
}
|
|
125
135
|
export {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
g as createSelector,
|
|
137
|
+
A as createStore,
|
|
138
|
+
L as link,
|
|
129
139
|
m as selector
|
|
130
140
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const c=require("react");function y(r){const{state:e,on:n,actions:i}=r;function a(t){const[p,d]=c.useState(typeof t=="function"?t(e()):e());return c.useEffect(()=>n(u=>{const o=typeof t=="function"?t(u):u;d(s=>Object.is(s,o)?s:o)}),[n,t]),p}function f(){return i}function S(){return n}return{useStore:a,useStoreActions:f,useStoreListeners:S}}module.exports=y;
|
package/dist/minirdx.react.es.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { useState as d, useEffect as m } from "react";
|
|
2
|
-
function
|
|
3
|
-
const { state: e, on:
|
|
4
|
-
function
|
|
5
|
-
const [
|
|
2
|
+
function j(c) {
|
|
3
|
+
const { state: e, on: n, actions: i } = c;
|
|
4
|
+
function r(t) {
|
|
5
|
+
const [S, p] = d(
|
|
6
6
|
typeof t == "function" ? t(e()) : e()
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
);
|
|
8
|
+
return m(() => n((o) => {
|
|
9
|
+
const u = typeof t == "function" ? t(o) : o;
|
|
10
|
+
p((s) => Object.is(s, u) ? s : u);
|
|
11
|
+
}), [n, t]), S;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
return
|
|
13
|
+
function f() {
|
|
14
|
+
return i;
|
|
15
15
|
}
|
|
16
16
|
function a() {
|
|
17
|
-
return
|
|
17
|
+
return n;
|
|
18
18
|
}
|
|
19
|
-
return { useStore:
|
|
19
|
+
return { useStore: r, useStoreActions: f, useStoreListeners: a };
|
|
20
20
|
}
|
|
21
21
|
export {
|
|
22
|
-
|
|
22
|
+
j as default
|
|
23
23
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Store, Action } from './index';
|
|
2
2
|
export default function createStoreHooks<S, A extends Record<string, Action<S>>>(store: Store<S, A>): {
|
|
3
|
-
useStore: <T = S>(selector?: (state: S) => T) =>
|
|
3
|
+
useStore: <T = S>(selector?: (state: S) => T) => T;
|
|
4
4
|
useStoreActions: () => Store<S, A>["actions"];
|
|
5
5
|
useStoreListeners: () => (action: keyof A | ((state: S, actionName: keyof A) => void), listener?: ((state: S, actionName: keyof A) => void) | undefined) => () => void;
|
|
6
6
|
};
|