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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as C } from "react/jsx-runtime";
2
- import f from "react";
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 h(e, r) {
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 v = c.value;
89
- v.remove(this);
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 b = w(P), p = b.next(); !p.done; p = b.next()) {
114
- var V = p.value;
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
- p && !p.done && (o = b.return) && o.call(b);
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 H = {
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 q(e) {
184
- $.setTimeout(function() {
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
- h(r, e);
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 = J, n;
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), D = (function() {
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
- h(r, e);
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 D(s), i;
263
+ } : s = t, i.destination = new G(s), i;
264
264
  }
265
265
  return r;
266
266
  })(F);
267
267
  function d(e) {
268
- q(e);
268
+ D(e);
269
269
  }
270
- function G(e) {
270
+ function J(e) {
271
271
  throw e;
272
272
  }
273
- var J = {
273
+ var K = {
274
274
  closed: !0,
275
275
  next: I,
276
- error: G,
276
+ error: J,
277
277
  complete: I
278
- }, K = (function() {
278
+ }, L = (function() {
279
279
  return typeof Symbol == "function" && Symbol.observable || "@@observable";
280
280
  })();
281
- function L(e) {
281
+ function Q(e) {
282
282
  return e;
283
283
  }
284
- function Q(e) {
285
- return e.length === 0 ? L : e.length === 1 ? e[0] : function(t) {
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 = X(r) ? r : new O(r, t, n);
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[K] = function() {
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 Q(r)(this);
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 ?? H.Promise) !== null && r !== void 0 ? r : Promise;
353
+ return (r = e ?? $.Promise) !== null && r !== void 0 ? r : Promise;
354
354
  }
355
- function W(e) {
355
+ function X(e) {
356
356
  return e && l(e.next) && l(e.error) && l(e.complete);
357
357
  }
358
- function X(e) {
359
- return e && e instanceof F || W(e) && Y(e);
358
+ function Z(e) {
359
+ return e && e instanceof F || X(e) && Y(e);
360
360
  }
361
- var Z = U(function(e) {
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
- h(r, e);
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 Z();
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 (v) {
389
- o = { error: v };
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
- h(r, e);
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), z = (function(e) {
464
- h(r, e);
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 rt {
487
+ class et {
488
488
  _stateSubject;
489
489
  constructor() {
490
- this.state = this.getInitialState(), this._stateSubject = new z(this.getInitialState());
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 et(e) {
504
- const r = f.createContext(void 0);
503
+ function nt(e) {
504
+ const r = b.createContext(void 0);
505
505
  function t() {
506
- const n = f.useContext(r);
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 [o, i] = f.useState(n.getState());
520
- return f.useEffect(() => {
521
- const s = n.state$().subscribe(i);
522
- return () => s.unsubscribe();
523
- }, []), n.state = o, n;
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 = f.useRef(new e());
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 = f.useRef(s());
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
- rt as Store,
549
- et as createStoreHook
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,KAAK,MAAM,OAAO,CAAC;AAC1B,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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-scoped-state",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {