context-scoped-state 0.0.7 → 0.0.8
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/index.js +58 -53
- package/dist/lib/createStore.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as C } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import b, { useSyncExternalStore as H } from "react";
|
|
3
3
|
var _ = function(e, r) {
|
|
4
4
|
return _ = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) {
|
|
5
5
|
t.__proto__ = n;
|
|
@@ -7,7 +7,7 @@ var _ = function(e, r) {
|
|
|
7
7
|
for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
|
|
8
8
|
}, _(e, r);
|
|
9
9
|
};
|
|
10
|
-
function
|
|
10
|
+
function p(e, r) {
|
|
11
11
|
if (typeof r != "function" && r !== null)
|
|
12
12
|
throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
|
|
13
13
|
_(e, r);
|
|
@@ -85,8 +85,8 @@ var S = (function() {
|
|
|
85
85
|
if (this._parentage = null, Array.isArray(s))
|
|
86
86
|
try {
|
|
87
87
|
for (var u = w(s), c = u.next(); !c.done; c = u.next()) {
|
|
88
|
-
var
|
|
89
|
-
|
|
88
|
+
var h = c.value;
|
|
89
|
+
h.remove(this);
|
|
90
90
|
}
|
|
91
91
|
} catch (a) {
|
|
92
92
|
r = { error: a };
|
|
@@ -110,8 +110,8 @@ var S = (function() {
|
|
|
110
110
|
if (P) {
|
|
111
111
|
this._finalizers = null;
|
|
112
112
|
try {
|
|
113
|
-
for (var
|
|
114
|
-
var V =
|
|
113
|
+
for (var v = w(P), f = v.next(); !f.done; f = v.next()) {
|
|
114
|
+
var V = f.value;
|
|
115
115
|
try {
|
|
116
116
|
A(V);
|
|
117
117
|
} catch (a) {
|
|
@@ -122,7 +122,7 @@ var S = (function() {
|
|
|
122
122
|
n = { error: a };
|
|
123
123
|
} finally {
|
|
124
124
|
try {
|
|
125
|
-
|
|
125
|
+
f && !f.done && (o = v.return) && o.call(v);
|
|
126
126
|
} finally {
|
|
127
127
|
if (n) throw n.error;
|
|
128
128
|
}
|
|
@@ -167,9 +167,9 @@ function Y(e) {
|
|
|
167
167
|
function A(e) {
|
|
168
168
|
l(e) ? e() : e.unsubscribe();
|
|
169
169
|
}
|
|
170
|
-
var
|
|
170
|
+
var $ = {
|
|
171
171
|
Promise: void 0
|
|
172
|
-
},
|
|
172
|
+
}, q = {
|
|
173
173
|
setTimeout: function(e, r) {
|
|
174
174
|
for (var t = [], n = 2; n < arguments.length; n++)
|
|
175
175
|
t[n - 2] = arguments[n];
|
|
@@ -180,8 +180,8 @@ var H = {
|
|
|
180
180
|
},
|
|
181
181
|
delegate: void 0
|
|
182
182
|
};
|
|
183
|
-
function
|
|
184
|
-
|
|
183
|
+
function D(e) {
|
|
184
|
+
q.setTimeout(function() {
|
|
185
185
|
throw e;
|
|
186
186
|
});
|
|
187
187
|
}
|
|
@@ -191,10 +191,10 @@ function y(e) {
|
|
|
191
191
|
e();
|
|
192
192
|
}
|
|
193
193
|
var F = (function(e) {
|
|
194
|
-
|
|
194
|
+
p(r, e);
|
|
195
195
|
function r(t) {
|
|
196
196
|
var n = e.call(this) || this;
|
|
197
|
-
return n.isStopped = !1, t ? (n.destination = t, Y(t) && t.add(n)) : n.destination =
|
|
197
|
+
return n.isStopped = !1, t ? (n.destination = t, Y(t) && t.add(n)) : n.destination = K, n;
|
|
198
198
|
}
|
|
199
199
|
return r.create = function(t, n, o) {
|
|
200
200
|
return new O(t, n, o);
|
|
@@ -221,7 +221,7 @@ var F = (function(e) {
|
|
|
221
221
|
this.unsubscribe();
|
|
222
222
|
}
|
|
223
223
|
}, r;
|
|
224
|
-
})(S),
|
|
224
|
+
})(S), G = (function() {
|
|
225
225
|
function e(r) {
|
|
226
226
|
this.partialObserver = r;
|
|
227
227
|
}
|
|
@@ -253,36 +253,36 @@ var F = (function(e) {
|
|
|
253
253
|
}
|
|
254
254
|
}, e;
|
|
255
255
|
})(), O = (function(e) {
|
|
256
|
-
|
|
256
|
+
p(r, e);
|
|
257
257
|
function r(t, n, o) {
|
|
258
258
|
var i = e.call(this) || this, s;
|
|
259
259
|
return l(t) || !t ? s = {
|
|
260
260
|
next: t ?? void 0,
|
|
261
261
|
error: n ?? void 0,
|
|
262
262
|
complete: o ?? void 0
|
|
263
|
-
} : s = t, i.destination = new
|
|
263
|
+
} : s = t, i.destination = new G(s), i;
|
|
264
264
|
}
|
|
265
265
|
return r;
|
|
266
266
|
})(F);
|
|
267
267
|
function d(e) {
|
|
268
|
-
|
|
268
|
+
D(e);
|
|
269
269
|
}
|
|
270
|
-
function
|
|
270
|
+
function J(e) {
|
|
271
271
|
throw e;
|
|
272
272
|
}
|
|
273
|
-
var
|
|
273
|
+
var K = {
|
|
274
274
|
closed: !0,
|
|
275
275
|
next: I,
|
|
276
|
-
error:
|
|
276
|
+
error: J,
|
|
277
277
|
complete: I
|
|
278
|
-
},
|
|
278
|
+
}, L = (function() {
|
|
279
279
|
return typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
280
280
|
})();
|
|
281
|
-
function
|
|
281
|
+
function Q(e) {
|
|
282
282
|
return e;
|
|
283
283
|
}
|
|
284
|
-
function
|
|
285
|
-
return e.length === 0 ?
|
|
284
|
+
function W(e) {
|
|
285
|
+
return e.length === 0 ? Q : e.length === 1 ? e[0] : function(t) {
|
|
286
286
|
return e.reduce(function(n, o) {
|
|
287
287
|
return o(n);
|
|
288
288
|
}, t);
|
|
@@ -296,7 +296,7 @@ var T = (function() {
|
|
|
296
296
|
var t = new e();
|
|
297
297
|
return t.source = this, t.operator = r, t;
|
|
298
298
|
}, e.prototype.subscribe = function(r, t, n) {
|
|
299
|
-
var o = this, i =
|
|
299
|
+
var o = this, i = Z(r) ? r : new O(r, t, n);
|
|
300
300
|
return y(function() {
|
|
301
301
|
var s = o, u = s.operator, c = s.source;
|
|
302
302
|
i.add(u ? u.call(i, c) : c ? o._subscribe(i) : o._trySubscribe(i));
|
|
@@ -326,12 +326,12 @@ var T = (function() {
|
|
|
326
326
|
}, e.prototype._subscribe = function(r) {
|
|
327
327
|
var t;
|
|
328
328
|
return (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(r);
|
|
329
|
-
}, e.prototype[
|
|
329
|
+
}, e.prototype[L] = function() {
|
|
330
330
|
return this;
|
|
331
331
|
}, e.prototype.pipe = function() {
|
|
332
332
|
for (var r = [], t = 0; t < arguments.length; t++)
|
|
333
333
|
r[t] = arguments[t];
|
|
334
|
-
return
|
|
334
|
+
return W(r)(this);
|
|
335
335
|
}, e.prototype.toPromise = function(r) {
|
|
336
336
|
var t = this;
|
|
337
337
|
return r = k(r), new r(function(n, o) {
|
|
@@ -350,20 +350,20 @@ var T = (function() {
|
|
|
350
350
|
})();
|
|
351
351
|
function k(e) {
|
|
352
352
|
var r;
|
|
353
|
-
return (r = e ??
|
|
353
|
+
return (r = e ?? $.Promise) !== null && r !== void 0 ? r : Promise;
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function X(e) {
|
|
356
356
|
return e && l(e.next) && l(e.error) && l(e.complete);
|
|
357
357
|
}
|
|
358
|
-
function
|
|
359
|
-
return e && e instanceof F ||
|
|
358
|
+
function Z(e) {
|
|
359
|
+
return e && e instanceof F || X(e) && Y(e);
|
|
360
360
|
}
|
|
361
|
-
var
|
|
361
|
+
var z = U(function(e) {
|
|
362
362
|
return function() {
|
|
363
363
|
e(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
|
|
364
364
|
};
|
|
365
365
|
}), B = (function(e) {
|
|
366
|
-
|
|
366
|
+
p(r, e);
|
|
367
367
|
function r() {
|
|
368
368
|
var t = e.call(this) || this;
|
|
369
369
|
return t.closed = !1, t.currentObservers = null, t.observers = [], t.isStopped = !1, t.hasError = !1, t.thrownError = null, t;
|
|
@@ -373,7 +373,7 @@ var Z = U(function(e) {
|
|
|
373
373
|
return n.operator = t, n;
|
|
374
374
|
}, r.prototype._throwIfClosed = function() {
|
|
375
375
|
if (this.closed)
|
|
376
|
-
throw new
|
|
376
|
+
throw new z();
|
|
377
377
|
}, r.prototype.next = function(t) {
|
|
378
378
|
var n = this;
|
|
379
379
|
y(function() {
|
|
@@ -385,8 +385,8 @@ var Z = U(function(e) {
|
|
|
385
385
|
var c = u.value;
|
|
386
386
|
c.next(t);
|
|
387
387
|
}
|
|
388
|
-
} catch (
|
|
389
|
-
o = { error:
|
|
388
|
+
} catch (h) {
|
|
389
|
+
o = { error: h };
|
|
390
390
|
} finally {
|
|
391
391
|
try {
|
|
392
392
|
u && !u.done && (i = s.return) && i.call(s);
|
|
@@ -442,7 +442,7 @@ var Z = U(function(e) {
|
|
|
442
442
|
return new R(t, n);
|
|
443
443
|
}, r;
|
|
444
444
|
})(T), R = (function(e) {
|
|
445
|
-
|
|
445
|
+
p(r, e);
|
|
446
446
|
function r(t, n) {
|
|
447
447
|
var o = e.call(this) || this;
|
|
448
448
|
return o.destination = t, o.source = n, o;
|
|
@@ -460,8 +460,8 @@ var Z = U(function(e) {
|
|
|
460
460
|
var n, o;
|
|
461
461
|
return (o = (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t)) !== null && o !== void 0 ? o : M;
|
|
462
462
|
}, r;
|
|
463
|
-
})(B),
|
|
464
|
-
|
|
463
|
+
})(B), N = (function(e) {
|
|
464
|
+
p(r, e);
|
|
465
465
|
function r(t) {
|
|
466
466
|
var n = e.call(this) || this;
|
|
467
467
|
return n._value = t, n;
|
|
@@ -484,10 +484,10 @@ var Z = U(function(e) {
|
|
|
484
484
|
e.prototype.next.call(this, this._value = t);
|
|
485
485
|
}, r;
|
|
486
486
|
})(B);
|
|
487
|
-
class
|
|
487
|
+
class et {
|
|
488
488
|
_stateSubject;
|
|
489
489
|
constructor() {
|
|
490
|
-
this.state = this.getInitialState(), this._stateSubject = new
|
|
490
|
+
this.state = this.getInitialState(), this._stateSubject = new N(this.getInitialState());
|
|
491
491
|
}
|
|
492
492
|
getState() {
|
|
493
493
|
return this._stateSubject.value;
|
|
@@ -500,10 +500,10 @@ class rt {
|
|
|
500
500
|
this._stateSubject.next(r);
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
|
-
function
|
|
504
|
-
const r =
|
|
503
|
+
function nt(e) {
|
|
504
|
+
const r = b.createContext(void 0);
|
|
505
505
|
function t() {
|
|
506
|
-
const n =
|
|
506
|
+
const n = b.useContext(r);
|
|
507
507
|
if (!n)
|
|
508
508
|
throw new Error(
|
|
509
509
|
`Store hook used outside of its Context provider.
|
|
@@ -516,16 +516,21 @@ Then wrap your component with:
|
|
|
516
516
|
<YourComponent />
|
|
517
517
|
</useYourStore.Context>`
|
|
518
518
|
);
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
519
|
+
const o = H(
|
|
520
|
+
(i) => {
|
|
521
|
+
const s = n.state$().subscribe(i);
|
|
522
|
+
return () => s.unsubscribe();
|
|
523
|
+
},
|
|
524
|
+
() => n.getState(),
|
|
525
|
+
() => n.getState()
|
|
526
|
+
// getServerSnapshot for SSR
|
|
527
|
+
);
|
|
528
|
+
return n.state = o, n;
|
|
524
529
|
}
|
|
525
530
|
return t.Context = function({
|
|
526
531
|
children: o
|
|
527
532
|
}) {
|
|
528
|
-
const i =
|
|
533
|
+
const i = b.useRef(new e());
|
|
529
534
|
return /* @__PURE__ */ C(r.Provider, { value: i.current, children: o });
|
|
530
535
|
}, t.MockContext = function({
|
|
531
536
|
children: o,
|
|
@@ -540,11 +545,11 @@ Then wrap your component with:
|
|
|
540
545
|
}
|
|
541
546
|
}
|
|
542
547
|
return new c();
|
|
543
|
-
}, u =
|
|
548
|
+
}, u = b.useRef(s());
|
|
544
549
|
return /* @__PURE__ */ C(r.Provider, { value: u.current, children: o });
|
|
545
550
|
}, t;
|
|
546
551
|
}
|
|
547
552
|
export {
|
|
548
|
-
|
|
549
|
-
|
|
553
|
+
et as Store,
|
|
554
|
+
nt as createStoreHook
|
|
550
555
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createStore.d.ts","sourceRoot":"","sources":["../../src/lib/createStore.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createStore.d.ts","sourceRoot":"","sources":["../../src/lib/createStore.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+B,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,iBAAS,eAAe,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC;QAG/C,CAAC;2BA+BnB;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;KAC3B;sCAaE;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;KACnC;EAuBF;AACD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|