@solid-primitives/utils 0.4.0 → 0.5.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/dist/index.cjs +25 -0
- package/dist/index.d.ts +36 -1
- package/dist/index.js +24 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,8 @@ __export(src_exports, {
|
|
|
33
33
|
createCallbackStack: () => createCallbackStack,
|
|
34
34
|
createMicrotask: () => createMicrotask,
|
|
35
35
|
createProxy: () => createProxy,
|
|
36
|
+
createTrigger: () => createTrigger,
|
|
37
|
+
createTriggerCache: () => createTriggerCache,
|
|
36
38
|
definite: () => definite,
|
|
37
39
|
destore: () => destore,
|
|
38
40
|
entries: () => entries,
|
|
@@ -162,6 +164,27 @@ function createProxy(traps) {
|
|
|
162
164
|
}
|
|
163
165
|
});
|
|
164
166
|
}
|
|
167
|
+
function createTrigger() {
|
|
168
|
+
return (0, import_solid_js.createSignal)(void 0, { equals: false });
|
|
169
|
+
}
|
|
170
|
+
function createTriggerCache() {
|
|
171
|
+
const cache = /* @__PURE__ */ new Map();
|
|
172
|
+
return {
|
|
173
|
+
dirty: (key) => {
|
|
174
|
+
var _a;
|
|
175
|
+
return (_a = cache.get(key)) == null ? void 0 : _a[1]();
|
|
176
|
+
},
|
|
177
|
+
dirtyAll: () => cache.forEach((s) => s[1]()),
|
|
178
|
+
track(key) {
|
|
179
|
+
let trigger = cache.get(key);
|
|
180
|
+
if (!trigger) {
|
|
181
|
+
trigger = createTrigger();
|
|
182
|
+
cache.set(key, trigger);
|
|
183
|
+
}
|
|
184
|
+
trigger[0]();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
165
188
|
module.exports = __toCommonJS(src_exports);
|
|
166
189
|
// Annotate the CommonJS export names for ESM import in node:
|
|
167
190
|
0 && (module.exports = {
|
|
@@ -174,6 +197,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
174
197
|
createCallbackStack,
|
|
175
198
|
createMicrotask,
|
|
176
199
|
createProxy,
|
|
200
|
+
createTrigger,
|
|
201
|
+
createTriggerCache,
|
|
177
202
|
definite,
|
|
178
203
|
destore,
|
|
179
204
|
entries,
|
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,12 @@ declare type Fallback<T, F = NonNullable<T>> = NonNullable<T> | F;
|
|
|
71
71
|
declare type Destore<T extends Object> = {
|
|
72
72
|
[K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
|
|
73
73
|
};
|
|
74
|
+
declare type TriggerCache<T> = {
|
|
75
|
+
track: Get<T>;
|
|
76
|
+
dirty: Get<T>;
|
|
77
|
+
dirtyAll: Fn;
|
|
78
|
+
};
|
|
79
|
+
declare type Trigger = [track: Fn, dirty: Fn];
|
|
74
80
|
declare type Position = {
|
|
75
81
|
x: number;
|
|
76
82
|
y: number;
|
|
@@ -266,5 +272,34 @@ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
|
|
|
266
272
|
get: <K extends keyof T>(key: K) => T[K];
|
|
267
273
|
set?: undefined;
|
|
268
274
|
}): Readonly<T>;
|
|
275
|
+
/**
|
|
276
|
+
* Set listeners in reactive computations and then trigger them when you want.
|
|
277
|
+
* @returns `[track function, dirty function]`
|
|
278
|
+
* @example
|
|
279
|
+
* const [track, dirty] = createTrigger()
|
|
280
|
+
* createEffect(() => {
|
|
281
|
+
* track()
|
|
282
|
+
* ...
|
|
283
|
+
* })
|
|
284
|
+
* // later
|
|
285
|
+
* dirty()
|
|
286
|
+
*/
|
|
287
|
+
declare function createTrigger(): Trigger;
|
|
288
|
+
/**
|
|
289
|
+
* Set listeners in reactive computations and then trigger them when you want. Cache trackers by a `key`.
|
|
290
|
+
* @returns `{ track, dirty, dirtyAll }` functions
|
|
291
|
+
* `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.
|
|
292
|
+
* @example
|
|
293
|
+
* const { track, dirty } = createTriggerCache()
|
|
294
|
+
* createEffect(() => {
|
|
295
|
+
* track(1)
|
|
296
|
+
* ...
|
|
297
|
+
* })
|
|
298
|
+
* // later
|
|
299
|
+
* dirty(1)
|
|
300
|
+
* // this won't cause an update:
|
|
301
|
+
* dirty(2)
|
|
302
|
+
*/
|
|
303
|
+
declare function createTriggerCache<T>(): TriggerCache<T>;
|
|
269
304
|
|
|
270
|
-
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, Clear, DeepPartialAny, Destore, Directive, ExtractIfPossible, Fallback, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, createMicrotask, createProxy, definite, destore, entries, forEach, forEachEntry, includes, isArray, isBoolean, isClient, isDefined, isDev, isFunction, isNumber, isObject, isProd, isString, keys, noop, ofClass, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, warn, withAccess, withFallback, withFallbackFn };
|
|
305
|
+
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, Clear, DeepPartialAny, Destore, Directive, ExtractIfPossible, Fallback, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Trigger, TriggerCache, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, createMicrotask, createProxy, createTrigger, createTriggerCache, definite, destore, entries, forEach, forEachEntry, includes, isArray, isBoolean, isClient, isDefined, isDev, isFunction, isNumber, isObject, isProd, isString, keys, noop, ofClass, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, warn, withAccess, withFallback, withFallbackFn };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { getOwner, onCleanup, on, DEV } from "solid-js";
|
|
2
|
+
import { getOwner, onCleanup, on, createSignal, DEV } from "solid-js";
|
|
3
3
|
import { isServer } from "solid-js/web";
|
|
4
4
|
var noop = () => void 0;
|
|
5
5
|
var isClient = !isServer;
|
|
@@ -98,6 +98,27 @@ function createProxy(traps) {
|
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
function createTrigger() {
|
|
102
|
+
return createSignal(void 0, { equals: false });
|
|
103
|
+
}
|
|
104
|
+
function createTriggerCache() {
|
|
105
|
+
const cache = /* @__PURE__ */ new Map();
|
|
106
|
+
return {
|
|
107
|
+
dirty: (key) => {
|
|
108
|
+
var _a;
|
|
109
|
+
return (_a = cache.get(key)) == null ? void 0 : _a[1]();
|
|
110
|
+
},
|
|
111
|
+
dirtyAll: () => cache.forEach((s) => s[1]()),
|
|
112
|
+
track(key) {
|
|
113
|
+
let trigger = cache.get(key);
|
|
114
|
+
if (!trigger) {
|
|
115
|
+
trigger = createTrigger();
|
|
116
|
+
cache.set(key, trigger);
|
|
117
|
+
}
|
|
118
|
+
trigger[0]();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
101
122
|
export {
|
|
102
123
|
access,
|
|
103
124
|
accessArray,
|
|
@@ -108,6 +129,8 @@ export {
|
|
|
108
129
|
createCallbackStack,
|
|
109
130
|
createMicrotask,
|
|
110
131
|
createProxy,
|
|
132
|
+
createTrigger,
|
|
133
|
+
createTriggerCache,
|
|
111
134
|
definite,
|
|
112
135
|
destore,
|
|
113
136
|
entries,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
|
|
5
5
|
"author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
|
|
6
6
|
"license": "MIT",
|