seitu 0.5.3 → 0.6.0

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.
@@ -1,5 +1,11 @@
1
+ export interface SubscribeOptions {
2
+ /**
3
+ * When `true`, the callback is invoked immediately with the current value upon subscribing.
4
+ */
5
+ immediate?: boolean;
6
+ }
1
7
  export interface Subscribable<V> {
2
- 'subscribe': (callback: (value: V) => any) => () => void;
8
+ 'subscribe': (callback: (value: V) => any, options?: SubscribeOptions) => () => void;
3
9
  '~': {
4
10
  /**
5
11
  * Type type with returned value of the subscription.
@@ -23,7 +29,7 @@ export interface Removable {
23
29
  export interface Destroyable {
24
30
  destroy: () => void;
25
31
  }
26
- export declare function createSubscription<T = void>(): {
27
- subscribe: (callback: (payload: T) => any) => () => void;
28
- notify: (payload: T) => void;
32
+ export declare function createSubscription(): {
33
+ subscribe: (callback: () => any, options?: SubscribeOptions) => () => void;
34
+ notify: () => void;
29
35
  };
@@ -2,13 +2,13 @@
2
2
  function e() {
3
3
  let e = /* @__PURE__ */ new Set();
4
4
  return {
5
- subscribe(t) {
6
- return e.add(t), () => {
5
+ subscribe(t, n) {
6
+ return n?.immediate && t(), e.add(t), () => {
7
7
  e.delete(t);
8
8
  };
9
9
  },
10
- notify(t) {
11
- e.forEach((e) => e(t));
10
+ notify() {
11
+ e.forEach((e) => e());
12
12
  }
13
13
  };
14
14
  }
@@ -19,8 +19,8 @@ function t(t, n) {
19
19
  for (let e of a) e.subscribe(() => i());
20
20
  return {
21
21
  get: s,
22
- subscribe(e) {
23
- return r(() => e(s()));
22
+ subscribe(e, t) {
23
+ return r(() => e(s()), t);
24
24
  },
25
25
  "~": {
26
26
  output: null,
@@ -57,9 +57,7 @@ function r(t) {
57
57
  s.set(t), a();
58
58
  },
59
59
  getDefaultValue: (e) => o[e],
60
- subscribe: (e) => r(() => {
61
- e(c());
62
- }),
60
+ subscribe: (e, t) => r(() => e(c()), t),
63
61
  destroy: () => {
64
62
  s.destroy?.();
65
63
  },
@@ -88,8 +86,8 @@ function a(t) {
88
86
  let t = typeof e == "function" ? e(n) : e;
89
87
  t !== n && (n = t, i());
90
88
  },
91
- subscribe(e) {
92
- return r(() => e(a()));
89
+ subscribe(e, t) {
90
+ return r(() => e(a()), t);
93
91
  },
94
92
  "~": {
95
93
  output: null,
package/dist/core.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, n as t, o as n, r, t as i } from "./core-3fd1NXIt.js";
1
+ import { a as e, n as t, o as n, r, t as i } from "./core-DLt97Ptv.js";
2
2
  export { e as createComputed, t as createSchemaStore, r as createSchemaStoreMemoryProvider, i as createStore, n as createSubscription };
package/dist/web.js CHANGED
@@ -1,10 +1,10 @@
1
- import { i as e, n as t, o as n } from "./core-3fd1NXIt.js";
1
+ import { i as e, n as t, o as n } from "./core-DLt97Ptv.js";
2
2
  //#region src/web/is-online.ts
3
3
  function r() {
4
4
  let { subscribe: e, notify: t } = n(), r = () => typeof navigator > "u" ? !0 : navigator.onLine, i = () => t();
5
5
  return typeof window < "u" && (window.addEventListener("online", i), window.addEventListener("offline", i)), {
6
6
  get: r,
7
- subscribe: (t) => e(() => t(r())),
7
+ subscribe: (t, n) => e(() => t(r()), n),
8
8
  destroy: () => {
9
9
  typeof window < "u" && (window.removeEventListener("online", i), window.removeEventListener("offline", i));
10
10
  },
@@ -53,17 +53,20 @@ function i(n) {
53
53
  let t = window[n.kind];
54
54
  r = !0, Object.entries(e).forEach(([e, r]) => {
55
55
  let i = typeof r == "string" ? r : JSON.stringify(r);
56
- t.setItem(n.keyTransform ? n.keyTransform(e) : e, i);
57
- }), window.dispatchEvent(new Event("storage")), r = !1;
56
+ t.setItem(n.keyTransform ? n.keyTransform(e) : e, i), window.dispatchEvent(new StorageEvent("storage", {
57
+ key: n.keyTransform ? n.keyTransform(e) : e,
58
+ newValue: i
59
+ }));
60
+ }), r = !1;
58
61
  }
59
62
  }
60
- }), a = Object.keys(n.schemas).map((e) => n.keyTransform ? n.keyTransform(e) : e), o = (e) => {
61
- r || e.key && a.includes(e.key) && i["~"].notify();
63
+ }), a = () => {
64
+ r || i["~"].notify();
62
65
  };
63
- return typeof window < "u" && window.addEventListener("storage", o), {
66
+ return typeof window < "u" && window.addEventListener("storage", a), {
64
67
  ...i,
65
68
  destroy: () => {
66
- i.destroy?.(), typeof window < "u" && window.removeEventListener("storage", o);
69
+ i.destroy?.(), typeof window < "u" && window.removeEventListener("storage", a);
67
70
  },
68
71
  "~": {
69
72
  kind: n.kind,
@@ -123,9 +126,12 @@ function o(t) {
123
126
  set: (e) => {
124
127
  if (typeof window > "u") return;
125
128
  let n = window[r], a = typeof e == "function" ? e(l()) : e;
126
- i = !0, n.setItem(t.key, typeof a == "string" ? a : JSON.stringify(a)), window.dispatchEvent(new Event("storage")), i = !1, c();
129
+ i = !0, n.setItem(t.key, typeof a == "string" ? a : JSON.stringify(a)), window.dispatchEvent(new StorageEvent("storage", {
130
+ key: t.key,
131
+ newValue: a
132
+ })), i = !1, c();
127
133
  },
128
- subscribe: (e) => s(() => e(l())),
134
+ subscribe: (e, t) => s(() => e(l()), t),
129
135
  remove: () => {
130
136
  typeof window > "u" || window[r].removeItem(t.key);
131
137
  },
@@ -152,7 +158,7 @@ function c(e) {
152
158
  let { subscribe: t, notify: r } = n(), i = typeof window > "u" ? null : window.matchMedia(e.query), a = () => i?.matches ?? e.defaultMatches ?? !1, o = () => r();
153
159
  return i?.addEventListener("change", o), {
154
160
  get: a,
155
- subscribe: (e) => t(() => e(a())),
161
+ subscribe: (e, n) => t(() => e(a()), n),
156
162
  destroy: () => {
157
163
  i?.removeEventListener("change", o);
158
164
  },
@@ -200,12 +206,12 @@ function u(e) {
200
206
  };
201
207
  return {
202
208
  get: c,
203
- subscribe: (e) => {
204
- let t = s();
205
- if (!t) return e(c()), () => {};
206
- let n = i(() => e(c())), r = () => e(c());
207
- return t.addEventListener("scroll", r, { passive: !0 }), () => {
208
- n(), t.removeEventListener("scroll", r);
209
+ subscribe: (e, t) => {
210
+ let n = s();
211
+ if (!n) return e(c()), () => {};
212
+ let r = i(() => e(c()), t), a = () => e(c());
213
+ return n.addEventListener("scroll", a, { passive: !0 }), () => {
214
+ r(), n.removeEventListener("scroll", a);
209
215
  };
210
216
  },
211
217
  "~": {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seitu",
3
3
  "displayName": "Seitu",
4
4
  "type": "module",
5
- "version": "0.5.3",
5
+ "version": "0.6.0",
6
6
  "private": false,
7
7
  "author": "Valerii Strilets",
8
8
  "license": "MIT",