context-scoped-state 0.0.9 → 0.0.11
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 +38 -35
- 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 p, { useSyncExternalStore as H } from "react";
|
|
3
3
|
var m = function(e, r) {
|
|
4
4
|
return m = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, n) {
|
|
5
5
|
t.__proto__ = n;
|
|
@@ -7,7 +7,7 @@ var m = function(e, r) {
|
|
|
7
7
|
for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]);
|
|
8
8
|
}, m(e, r);
|
|
9
9
|
};
|
|
10
|
-
function
|
|
10
|
+
function h(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
|
m(e, r);
|
|
@@ -51,13 +51,13 @@ function E(e, r, t) {
|
|
|
51
51
|
function l(e) {
|
|
52
52
|
return typeof e == "function";
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function M(e) {
|
|
55
55
|
var r = function(n) {
|
|
56
56
|
Error.call(n), n.stack = new Error().stack;
|
|
57
57
|
}, t = e(r);
|
|
58
58
|
return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
|
|
59
59
|
}
|
|
60
|
-
var _ =
|
|
60
|
+
var _ = M(function(e) {
|
|
61
61
|
return function(t) {
|
|
62
62
|
e(this), this.message = t ? t.length + ` errors occurred during unsubscription:
|
|
63
63
|
` + t.map(function(n, o) {
|
|
@@ -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 v = c.value;
|
|
89
|
+
v.remove(this);
|
|
90
90
|
}
|
|
91
91
|
} catch (a) {
|
|
92
92
|
r = { error: a };
|
|
@@ -110,7 +110,7 @@ var S = (function() {
|
|
|
110
110
|
if (P) {
|
|
111
111
|
this._finalizers = null;
|
|
112
112
|
try {
|
|
113
|
-
for (var
|
|
113
|
+
for (var b = w(P), f = b.next(); !f.done; f = b.next()) {
|
|
114
114
|
var V = f.value;
|
|
115
115
|
try {
|
|
116
116
|
A(V);
|
|
@@ -122,7 +122,7 @@ var S = (function() {
|
|
|
122
122
|
n = { error: a };
|
|
123
123
|
} finally {
|
|
124
124
|
try {
|
|
125
|
-
f && !f.done && (o =
|
|
125
|
+
f && !f.done && (o = b.return) && o.call(b);
|
|
126
126
|
} finally {
|
|
127
127
|
if (n) throw n.error;
|
|
128
128
|
}
|
|
@@ -160,8 +160,8 @@ var S = (function() {
|
|
|
160
160
|
var r = new e();
|
|
161
161
|
return r.closed = !0, r;
|
|
162
162
|
})(), e;
|
|
163
|
-
})(),
|
|
164
|
-
function
|
|
163
|
+
})(), Y = S.EMPTY;
|
|
164
|
+
function R(e) {
|
|
165
165
|
return e instanceof S || e && "closed" in e && l(e.remove) && l(e.add) && l(e.unsubscribe);
|
|
166
166
|
}
|
|
167
167
|
function A(e) {
|
|
@@ -191,10 +191,10 @@ function y(e) {
|
|
|
191
191
|
e();
|
|
192
192
|
}
|
|
193
193
|
var F = (function(e) {
|
|
194
|
-
|
|
194
|
+
h(r, e);
|
|
195
195
|
function r(t) {
|
|
196
196
|
var n = e.call(this) || this;
|
|
197
|
-
return n.isStopped = !1, t ? (n.destination = t,
|
|
197
|
+
return n.isStopped = !1, t ? (n.destination = t, R(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);
|
|
@@ -253,7 +253,7 @@ var F = (function(e) {
|
|
|
253
253
|
}
|
|
254
254
|
}, e;
|
|
255
255
|
})(), O = (function(e) {
|
|
256
|
-
|
|
256
|
+
h(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 = {
|
|
@@ -356,20 +356,20 @@ function X(e) {
|
|
|
356
356
|
return e && l(e.next) && l(e.error) && l(e.complete);
|
|
357
357
|
}
|
|
358
358
|
function Z(e) {
|
|
359
|
-
return e && e instanceof F || X(e) &&
|
|
359
|
+
return e && e instanceof F || X(e) && R(e);
|
|
360
360
|
}
|
|
361
|
-
var z =
|
|
361
|
+
var z = M(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
|
+
h(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;
|
|
370
370
|
}
|
|
371
371
|
return r.prototype.lift = function(t) {
|
|
372
|
-
var n = new
|
|
372
|
+
var n = new U(this, this);
|
|
373
373
|
return n.operator = t, n;
|
|
374
374
|
}, r.prototype._throwIfClosed = function() {
|
|
375
375
|
if (this.closed)
|
|
@@ -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 (v) {
|
|
389
|
+
o = { error: v };
|
|
390
390
|
} finally {
|
|
391
391
|
try {
|
|
392
392
|
u && !u.done && (i = s.return) && i.call(s);
|
|
@@ -429,7 +429,7 @@ var z = U(function(e) {
|
|
|
429
429
|
return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
|
|
430
430
|
}, r.prototype._innerSubscribe = function(t) {
|
|
431
431
|
var n = this, o = this, i = o.hasError, s = o.isStopped, u = o.observers;
|
|
432
|
-
return i || s ?
|
|
432
|
+
return i || s ? Y : (this.currentObservers = null, u.push(t), new S(function() {
|
|
433
433
|
n.currentObservers = null, g(u, t);
|
|
434
434
|
}));
|
|
435
435
|
}, r.prototype._checkFinalizedStatuses = function(t) {
|
|
@@ -439,10 +439,10 @@ var z = U(function(e) {
|
|
|
439
439
|
var t = new T();
|
|
440
440
|
return t.source = this, t;
|
|
441
441
|
}, r.create = function(t, n) {
|
|
442
|
-
return new
|
|
442
|
+
return new U(t, n);
|
|
443
443
|
}, r;
|
|
444
|
-
})(T),
|
|
445
|
-
|
|
444
|
+
})(T), U = (function(e) {
|
|
445
|
+
h(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;
|
|
@@ -458,10 +458,10 @@ var z = U(function(e) {
|
|
|
458
458
|
(n = (t = this.destination) === null || t === void 0 ? void 0 : t.complete) === null || n === void 0 || n.call(t);
|
|
459
459
|
}, r.prototype._subscribe = function(t) {
|
|
460
460
|
var n, o;
|
|
461
|
-
return (o = (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t)) !== null && o !== void 0 ? o :
|
|
461
|
+
return (o = (n = this.source) === null || n === void 0 ? void 0 : n.subscribe(t)) !== null && o !== void 0 ? o : Y;
|
|
462
462
|
}, r;
|
|
463
463
|
})(B), N = (function(e) {
|
|
464
|
-
|
|
464
|
+
h(r, e);
|
|
465
465
|
function r(t) {
|
|
466
466
|
var n = e.call(this) || this;
|
|
467
467
|
return n._value = t, n;
|
|
@@ -506,9 +506,9 @@ class et {
|
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
508
|
function nt(e) {
|
|
509
|
-
const r =
|
|
509
|
+
const r = p.createContext(void 0);
|
|
510
510
|
function t() {
|
|
511
|
-
const n =
|
|
511
|
+
const n = p.useContext(r);
|
|
512
512
|
if (!n)
|
|
513
513
|
throw new Error(
|
|
514
514
|
`Store hook used outside of its Context provider.
|
|
@@ -521,22 +521,25 @@ Then wrap your component with:
|
|
|
521
521
|
<YourComponent />
|
|
522
522
|
</useYourStore.Context>`
|
|
523
523
|
);
|
|
524
|
-
const o =
|
|
525
|
-
(
|
|
526
|
-
const
|
|
527
|
-
return () =>
|
|
524
|
+
const o = p.useCallback(
|
|
525
|
+
(s) => {
|
|
526
|
+
const u = n.state$().subscribe(s);
|
|
527
|
+
return () => u.unsubscribe();
|
|
528
528
|
},
|
|
529
|
+
[n]
|
|
530
|
+
), i = H(
|
|
531
|
+
o,
|
|
529
532
|
() => n.getState(),
|
|
530
533
|
() => n.getState()
|
|
531
534
|
// getServerSnapshot for SSR
|
|
532
535
|
);
|
|
533
|
-
return n.state =
|
|
536
|
+
return n.state = i, n;
|
|
534
537
|
}
|
|
535
538
|
return t.Context = function({
|
|
536
539
|
children: o
|
|
537
540
|
}) {
|
|
538
|
-
const i =
|
|
539
|
-
return /* @__PURE__ */ C(r.Provider, { value: i
|
|
541
|
+
const [i] = p.useState(() => new e());
|
|
542
|
+
return /* @__PURE__ */ C(r.Provider, { value: i, children: o });
|
|
540
543
|
}, t.MockContext = function({
|
|
541
544
|
children: o,
|
|
542
545
|
state: i
|
|
@@ -550,7 +553,7 @@ Then wrap your component with:
|
|
|
550
553
|
}
|
|
551
554
|
}
|
|
552
555
|
return new c();
|
|
553
|
-
}, u =
|
|
556
|
+
}, u = p.useRef(s());
|
|
554
557
|
return /* @__PURE__ */ C(r.Provider, { value: u.current, children: o });
|
|
555
558
|
}, t;
|
|
556
559
|
}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;2BAoCnB;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;KAC3B;sCAWE;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"}
|