@solid-primitives/utils 2.1.0 → 3.0.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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Solid Primitives Working Group
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Solid Primitives Working Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,46 +1,19 @@
1
- <p>
2
- <img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Utils" alt="Solid Primitives Utils">
3
- </p>
4
-
5
- # @solid-primitives/utils
6
-
7
- Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or centralize useful utilities and methods in this package for sharing.
8
-
9
- ## Installation
10
-
11
- ```bash
12
- npm install @solid-primitives/utils
13
- # or
14
- yarn add @solid-primitives/utils
15
- ```
16
-
17
- ## Changelog
18
-
19
- <details>
20
- <summary><b>Expand Changelog</b></summary>
21
-
22
- 0.0.100
23
-
24
- First commit of the timer primitive.
25
-
26
- 0.0.250
27
-
28
- Republished version with better ESM support and build tooling.
29
-
30
- 0.0.260
31
-
32
- Added comments for util methods.
33
-
34
- 0.1.0
35
-
36
- Add `/fp` and `/setter` export entries. Add `destore` and `raceTimeout` util. More jsdoc.
37
-
38
- 0.1.2
39
-
40
- Updated to Solid 1.3
41
-
42
- 0.1.3
43
-
44
- Minor upgrades.
45
-
46
- </details>
1
+ <p>
2
+ <img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Utils" alt="Solid Primitives Utils">
3
+ </p>
4
+
5
+ # @solid-primitives/utils
6
+
7
+ Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or centralize useful utilities and methods in this package for sharing.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @solid-primitives/utils
13
+ # or
14
+ yarn add @solid-primitives/utils
15
+ ```
16
+
17
+ ## Changelog
18
+
19
+ See [CHANGELOG.md](./CHANGELOG.md)
package/dist/index.cjs CHANGED
@@ -1,21 +1,8 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
6
  var __export = (target, all) => {
20
7
  for (var name in all)
21
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -36,6 +23,7 @@ __export(src_exports, {
36
23
  access: () => access,
37
24
  accessArray: () => accessArray,
38
25
  accessWith: () => accessWith,
26
+ arrayEquals: () => arrayEquals,
39
27
  asAccessor: () => asAccessor,
40
28
  asArray: () => asArray,
41
29
  chain: () => chain,
@@ -47,6 +35,7 @@ __export(src_exports, {
47
35
  createStaticStore: () => createStaticStore,
48
36
  createTrigger: () => createTrigger,
49
37
  createTriggerCache: () => createTriggerCache,
38
+ createWeakTriggerCache: () => createWeakTriggerCache,
50
39
  entries: () => entries,
51
40
  forEachEntry: () => forEachEntry,
52
41
  handleDiffArray: () => handleDiffArray,
@@ -59,8 +48,6 @@ __export(src_exports, {
59
48
  noop: () => noop,
60
49
  ofClass: () => ofClass,
61
50
  onRootCleanup: () => onRootCleanup,
62
- promiseTimeout: () => promiseTimeout,
63
- raceTimeout: () => raceTimeout,
64
51
  warn: () => warn,
65
52
  withAccess: () => withAccess
66
53
  });
@@ -78,6 +65,7 @@ function isObject(value) {
78
65
  return value !== null && (typeof value === "object" || typeof value === "function");
79
66
  }
80
67
  var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
68
+ var arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
81
69
  function chain(callbacks) {
82
70
  return (...args) => {
83
71
  for (const callback of callbacks) {
@@ -99,19 +87,12 @@ function accessWith(valueOrFn, ...args) {
99
87
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
100
88
  }
101
89
  function forEachEntry(object, iterator) {
102
- Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
90
+ Object.entries(object).forEach(
91
+ ([key, item], index, pairs) => iterator(key, item, index, pairs, object)
92
+ );
103
93
  }
104
94
  var entries = Object.entries;
105
95
  var keys = Object.keys;
106
- var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
107
- function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
108
- const promises = asArray(input);
109
- const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
110
- race.finally(() => {
111
- promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
112
- });
113
- return race;
114
- }
115
96
  var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
116
97
  var createCallbackStack = () => {
117
98
  let stack = [];
@@ -134,38 +115,54 @@ function createMicrotask(fn) {
134
115
  };
135
116
  }
136
117
  function createProxy(traps) {
137
- return new Proxy({}, {
138
- get: (_, k) => traps.get(k),
139
- set: (_, k, v) => {
140
- var _a;
141
- (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
142
- return false;
118
+ return new Proxy(
119
+ {},
120
+ {
121
+ get: (_, k) => traps.get(k),
122
+ set: (_, k, v) => {
123
+ var _a;
124
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
125
+ return false;
126
+ }
143
127
  }
144
- });
128
+ );
145
129
  }
146
- function createTrigger(options) {
147
- return (0, import_solid_js.createSignal)(void 0, { equals: false, name: options == null ? void 0 : options.name });
130
+ var createTrigger = isDev ? () => (0, import_solid_js.createSignal)(void 0, { equals: false, name: "trigger" }) : () => (0, import_solid_js.createSignal)(void 0, { equals: false });
131
+ function dirtyTriggerCache(key) {
132
+ const trigger = this.get(key);
133
+ if (trigger)
134
+ trigger[1]();
135
+ }
136
+ function dirtyAllTriggerCache() {
137
+ this.forEach((s) => s[1]());
138
+ }
139
+ function trackTriggerCache(key) {
140
+ if (!(0, import_solid_js.getListener)())
141
+ return;
142
+ let trigger = this.get(key);
143
+ if (!trigger) {
144
+ trigger = createTrigger();
145
+ this.set(key, trigger);
146
+ }
147
+ trigger[0]();
148
148
  }
149
- function createTriggerCache(options) {
149
+ function createTriggerCache() {
150
150
  const cache = /* @__PURE__ */ new Map();
151
151
  return {
152
- dirty: (key) => {
153
- var _a;
154
- return (_a = cache.get(key)) == null ? void 0 : _a[1]();
155
- },
156
- dirtyAll: () => cache.forEach((s) => s[1]()),
157
- track(key) {
158
- let trigger = cache.get(key);
159
- if (!trigger) {
160
- trigger = createTrigger(options);
161
- cache.set(key, trigger);
162
- }
163
- trigger[0]();
164
- }
152
+ dirty: dirtyTriggerCache.bind(cache),
153
+ dirtyAll: dirtyAllTriggerCache.bind(cache),
154
+ track: trackTriggerCache.bind(cache)
155
+ };
156
+ }
157
+ function createWeakTriggerCache() {
158
+ const cache = /* @__PURE__ */ new WeakMap();
159
+ return {
160
+ dirty: dirtyTriggerCache.bind(cache),
161
+ track: trackTriggerCache.bind(cache)
165
162
  };
166
163
  }
167
164
  function createStaticStore(init) {
168
- const copy = __spreadValues({}, init);
165
+ const copy = { ...init };
169
166
  const store = {};
170
167
  const cache = /* @__PURE__ */ new Map();
171
168
  const getValue = (key) => {
@@ -242,6 +239,7 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
242
239
  access,
243
240
  accessArray,
244
241
  accessWith,
242
+ arrayEquals,
245
243
  asAccessor,
246
244
  asArray,
247
245
  chain,
@@ -253,6 +251,7 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
253
251
  createStaticStore,
254
252
  createTrigger,
255
253
  createTriggerCache,
254
+ createWeakTriggerCache,
256
255
  entries,
257
256
  forEachEntry,
258
257
  handleDiffArray,
@@ -265,8 +264,6 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
265
264
  noop,
266
265
  ofClass,
267
266
  onRootCleanup,
268
- promiseTimeout,
269
- raceTimeout,
270
267
  warn,
271
268
  withAccess
272
269
  });
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Accessor, Setter, onCleanup } from 'solid-js';
2
- import { BaseOptions } from 'solid-js/types/reactive/signal';
3
2
 
4
3
  /**
5
4
  * Can be single or in an array
@@ -82,12 +81,6 @@ declare type PrimitiveValue = PropertyKey | boolean | bigint | null | undefined;
82
81
  declare type FalsyValue = false | 0 | "" | null | undefined;
83
82
  declare type Truthy<T> = Exclude<T, FalsyValue>;
84
83
  declare type Falsy<T> = Extract<T, FalsyValue>;
85
- declare type TriggerCache<T> = {
86
- track: (v: T) => void;
87
- dirty: (v: T) => void;
88
- dirtyAll: VoidFunction;
89
- };
90
- declare type Trigger = [track: VoidFunction, dirty: VoidFunction];
91
84
  declare type Position = {
92
85
  x: number;
93
86
  y: number;
@@ -110,6 +103,10 @@ declare const ofClass: (v: any, c: AnyClass) => boolean;
110
103
  /** Check if value is typeof "object" or "function" */
111
104
  declare function isObject(value: any): value is AnyObject;
112
105
  declare const compare: (a: any, b: any) => number;
106
+ /**
107
+ * Check shallow array equality
108
+ */
109
+ declare const arrayEquals: (a: readonly unknown[], b: readonly unknown[]) => boolean;
113
110
  /**
114
111
  * Returns a function that will call all functions in the order they were chained with the same arguments.
115
112
  */
@@ -155,42 +152,6 @@ declare const entries: <T extends object>(obj: T) => [keyof T, T[keyof T]][];
155
152
  * Get keys of an object
156
153
  */
157
154
  declare const keys: <T extends object>(object: T) => (keyof T)[];
158
- /**
159
- * Creates a promise that resolves *(or rejects)* after given time.
160
- *
161
- * @param ms timeout duration in ms
162
- * @param throwOnTimeout promise will be rejected on timeout if set to `true`
163
- * @param reason rejection reason
164
- * @returns Promise<void>
165
- *
166
- * @example
167
- * ```ts
168
- * await promiseTimeout(1500) // will resolve void after timeout
169
- * await promiseTimeout(1500, true, 'rejection reason') // will reject 'rejection reason' after timout
170
- * ```
171
- */
172
- declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>;
173
- /**
174
- * Combination of `Promise.race()` and `promiseTimeout`.
175
- *
176
- * @param promises single promise, or array of promises
177
- * @param ms timeout duration in ms
178
- * @param throwOnTimeout promise will be rejected on timeout if set to `true`
179
- * @param reason rejection reason
180
- * @returns a promise resulting in value of the first source promises to be resolved
181
- *
182
- * @example
183
- * ```ts
184
- * // single promise
185
- * await raceTimeout(new Promise(() => {...}), 3000)
186
- * // list of promises racing
187
- * await raceTimeout([new Promise(),new Promise()...], 3000)
188
- * // reject on timeout
189
- * await raceTimeout(new Promise(), 3000, true, 'rejection reason')
190
- * ```
191
- */
192
- declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
193
- declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
194
155
  /**
195
156
  * Solid's `onCleanup` that is registered only if there is a root.
196
157
  */
@@ -215,6 +176,7 @@ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
215
176
  get: <K extends keyof T>(key: K) => T[K];
216
177
  set?: undefined;
217
178
  }): Readonly<T>;
179
+ declare type Trigger = [track: VoidFunction, dirty: VoidFunction];
218
180
  /**
219
181
  * Set listeners in reactive computations and then trigger them when you want.
220
182
  * @returns `[track function, dirty function]`
@@ -227,7 +189,12 @@ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
227
189
  * // later
228
190
  * dirty()
229
191
  */
230
- declare function createTrigger(options?: BaseOptions): Trigger;
192
+ declare const createTrigger: () => Trigger;
193
+ declare type TriggerCache<T> = {
194
+ track: (v: T) => void;
195
+ dirty: (v: T) => void;
196
+ dirtyAll: VoidFunction;
197
+ };
231
198
  /**
232
199
  * Set listeners in reactive computations and then trigger them when you want. Cache trackers by a `key`.
233
200
  * @returns `{ track, dirty, dirtyAll }` functions
@@ -243,14 +210,34 @@ declare function createTrigger(options?: BaseOptions): Trigger;
243
210
  * // this won't cause an update:
244
211
  * dirty(2)
245
212
  */
246
- declare function createTriggerCache<T>(options?: BaseOptions): TriggerCache<T>;
213
+ declare function createTriggerCache<T>(): TriggerCache<T>;
214
+ declare type WeakTriggerCache<T extends object> = {
215
+ track: (v: T) => void;
216
+ dirty: (v: T) => void;
217
+ };
218
+ /**
219
+ * Set listeners in reactive computations and then trigger them when you want. Cache trackers by a `key`.
220
+ * @returns `{ track, dirty }` functions
221
+ * `track` and `dirty` are called with a `key` so that each tracker will trigger an update only when his individual `key` would get marked as dirty.
222
+ * @example
223
+ * const { track, dirty } = createWeakTriggerCache()
224
+ * createEffect(() => {
225
+ * track(1)
226
+ * ...
227
+ * })
228
+ * // later
229
+ * dirty(1)
230
+ * // this won't cause an update:
231
+ * dirty(2)
232
+ */
233
+ declare function createWeakTriggerCache<T extends object>(): WeakTriggerCache<T>;
247
234
  declare type StaticStoreSetter<T extends Readonly<AnyStatic>> = {
248
235
  (setter: (prev: T) => Partial<T>): T;
249
236
  (state: Partial<T>): T;
250
237
  <K extends keyof T>(key: K, state: SetterValue<T[K]>): T;
251
238
  };
252
239
  /**
253
- * A shallowly wrapped reactive store object. It behaves similarly to the creatStore, but with limited features to keep it simple. Designed to be used for reactive objects with static keys, but dynamic values, like reactive Event State, location, etc.
240
+ * A shallowly wrapped reactive store object. It behaves similarly to the createStore, but with limited features to keep it simple. Designed to be used for reactive objects with static keys, but dynamic values, like reactive Event State, location, etc.
254
241
  * @param init initial value of the store
255
242
  * @returns
256
243
  * ```ts
@@ -268,4 +255,4 @@ declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [acc
268
255
  */
269
256
  declare function handleDiffArray<T>(current: T[], prev: T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
270
257
 
271
- export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Mutable, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterValue, Simplify, StaticStoreSetter, Tail, Trigger, TriggerCache, Truthy, UnboxLazy, UnionToIntersection, Values, access, accessArray, accessWith, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createProxy, createStaticStore, createTrigger, createTriggerCache, entries, forEachEntry, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, onRootCleanup, promiseTimeout, raceTimeout, warn, withAccess };
258
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Mutable, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterValue, Simplify, StaticStoreSetter, Tail, Trigger, TriggerCache, Truthy, UnboxLazy, UnionToIntersection, Values, WeakTriggerCache, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createProxy, createStaticStore, createTrigger, createTriggerCache, createWeakTriggerCache, entries, forEachEntry, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, onRootCleanup, warn, withAccess };
package/dist/index.js CHANGED
@@ -1,22 +1,13 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
-
18
1
  // src/index.ts
19
- import { getOwner, onCleanup, createSignal, DEV, untrack, batch } from "solid-js";
2
+ import {
3
+ getOwner,
4
+ onCleanup,
5
+ createSignal,
6
+ DEV,
7
+ untrack,
8
+ batch,
9
+ getListener
10
+ } from "solid-js";
20
11
  import { isServer as _isServer } from "solid-js/web";
21
12
  var noop = () => void 0;
22
13
  var isServer = _isServer;
@@ -29,6 +20,7 @@ function isObject(value) {
29
20
  return value !== null && (typeof value === "object" || typeof value === "function");
30
21
  }
31
22
  var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
23
+ var arrayEquals = (a, b) => a === b || a.length === b.length && a.every((e, i) => e === b[i]);
32
24
  function chain(callbacks) {
33
25
  return (...args) => {
34
26
  for (const callback of callbacks) {
@@ -50,19 +42,12 @@ function accessWith(valueOrFn, ...args) {
50
42
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
51
43
  }
52
44
  function forEachEntry(object, iterator) {
53
- Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
45
+ Object.entries(object).forEach(
46
+ ([key, item], index, pairs) => iterator(key, item, index, pairs, object)
47
+ );
54
48
  }
55
49
  var entries = Object.entries;
56
50
  var keys = Object.keys;
57
- var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
58
- function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
59
- const promises = asArray(input);
60
- const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
61
- race.finally(() => {
62
- promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
63
- });
64
- return race;
65
- }
66
51
  var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
67
52
  var createCallbackStack = () => {
68
53
  let stack = [];
@@ -85,38 +70,54 @@ function createMicrotask(fn) {
85
70
  };
86
71
  }
87
72
  function createProxy(traps) {
88
- return new Proxy({}, {
89
- get: (_, k) => traps.get(k),
90
- set: (_, k, v) => {
91
- var _a;
92
- (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
93
- return false;
73
+ return new Proxy(
74
+ {},
75
+ {
76
+ get: (_, k) => traps.get(k),
77
+ set: (_, k, v) => {
78
+ var _a;
79
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
80
+ return false;
81
+ }
94
82
  }
95
- });
83
+ );
96
84
  }
97
- function createTrigger(options) {
98
- return createSignal(void 0, { equals: false, name: options == null ? void 0 : options.name });
85
+ var createTrigger = isDev ? () => createSignal(void 0, { equals: false, name: "trigger" }) : () => createSignal(void 0, { equals: false });
86
+ function dirtyTriggerCache(key) {
87
+ const trigger = this.get(key);
88
+ if (trigger)
89
+ trigger[1]();
90
+ }
91
+ function dirtyAllTriggerCache() {
92
+ this.forEach((s) => s[1]());
93
+ }
94
+ function trackTriggerCache(key) {
95
+ if (!getListener())
96
+ return;
97
+ let trigger = this.get(key);
98
+ if (!trigger) {
99
+ trigger = createTrigger();
100
+ this.set(key, trigger);
101
+ }
102
+ trigger[0]();
99
103
  }
100
- function createTriggerCache(options) {
104
+ function createTriggerCache() {
101
105
  const cache = /* @__PURE__ */ new Map();
102
106
  return {
103
- dirty: (key) => {
104
- var _a;
105
- return (_a = cache.get(key)) == null ? void 0 : _a[1]();
106
- },
107
- dirtyAll: () => cache.forEach((s) => s[1]()),
108
- track(key) {
109
- let trigger = cache.get(key);
110
- if (!trigger) {
111
- trigger = createTrigger(options);
112
- cache.set(key, trigger);
113
- }
114
- trigger[0]();
115
- }
107
+ dirty: dirtyTriggerCache.bind(cache),
108
+ dirtyAll: dirtyAllTriggerCache.bind(cache),
109
+ track: trackTriggerCache.bind(cache)
110
+ };
111
+ }
112
+ function createWeakTriggerCache() {
113
+ const cache = /* @__PURE__ */ new WeakMap();
114
+ return {
115
+ dirty: dirtyTriggerCache.bind(cache),
116
+ track: trackTriggerCache.bind(cache)
116
117
  };
117
118
  }
118
119
  function createStaticStore(init) {
119
- const copy = __spreadValues({}, init);
120
+ const copy = { ...init };
120
121
  const store = {};
121
122
  const cache = /* @__PURE__ */ new Map();
122
123
  const getValue = (key) => {
@@ -192,6 +193,7 @@ export {
192
193
  access,
193
194
  accessArray,
194
195
  accessWith,
196
+ arrayEquals,
195
197
  asAccessor,
196
198
  asArray,
197
199
  chain,
@@ -203,6 +205,7 @@ export {
203
205
  createStaticStore,
204
206
  createTrigger,
205
207
  createTriggerCache,
208
+ createWeakTriggerCache,
206
209
  entries,
207
210
  forEachEntry,
208
211
  handleDiffArray,
@@ -215,8 +218,6 @@ export {
215
218
  noop,
216
219
  ofClass,
217
220
  onRootCleanup,
218
- promiseTimeout,
219
- raceTimeout,
220
221
  warn,
221
222
  withAccess
222
223
  };
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "@solid-primitives/utils",
3
- "version": "2.1.0",
4
- "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
- "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
- "license": "MIT",
7
- "homepage": "https://github.com/solidjs-community/solid-primitives/tree/main/packages/utils#readme",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/solidjs-community/solid-primitives.git"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/solidjs-community/solid-primitives/issues"
14
- },
15
- "private": false,
16
- "sideEffects": false,
17
- "type": "module",
18
- "main": "dist/index.cjs",
19
- "module": "dist/index.js",
20
- "types": "dist/index.d.ts",
21
- "files": [
22
- "dist"
23
- ],
24
- "scripts": {
25
- "build": "tsup",
26
- "test": "uvu -r solid-register",
27
- "test:watch": "watchlist src test -- npm test"
28
- },
29
- "keywords": [
30
- "utilities",
31
- "reactivity",
32
- "solid",
33
- "primitives"
34
- ],
35
- "devDependencies": {
36
- "jsdom": "^19.0.0",
37
- "prettier": "^2.5.1",
38
- "solid-register": "^0.2.5",
39
- "tslib": "^2.3.1",
40
- "tsup": "^5.11.0",
41
- "uvu": "^0.5.2",
42
- "watchlist": "^0.3.1"
43
- },
44
- "peerDependencies": {
45
- "solid-js": "^1.4.1"
46
- }
47
- }
1
+ {
2
+ "name": "@solid-primitives/utils",
3
+ "version": "3.0.0",
4
+ "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
+ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/solidjs-community/solid-primitives/tree/main/packages/utils#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/solidjs-community/solid-primitives.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/solidjs-community/solid-primitives/issues"
14
+ },
15
+ "private": false,
16
+ "sideEffects": false,
17
+ "type": "module",
18
+ "main": "dist/index.cjs",
19
+ "module": "dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "keywords": [
25
+ "utilities",
26
+ "reactivity",
27
+ "solid",
28
+ "primitives"
29
+ ],
30
+ "devDependencies": {
31
+ "jsdom": "^19.0.0",
32
+ "prettier": "^2.7.1",
33
+ "solid-register": "^0.2.5",
34
+ "tslib": "^2.4.0",
35
+ "tsup": "^6.1.3",
36
+ "uvu": "^0.5.6",
37
+ "watchlist": "^0.3.1"
38
+ },
39
+ "peerDependencies": {
40
+ "solid-js": "^1.4.1"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "test": "uvu -r solid-register",
45
+ "test:watch": "watchlist src test -- npm test"
46
+ }
47
+ }