@solid-primitives/utils 2.1.1 → 2.2.1
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 +33 -31
- package/dist/index.d.ts +30 -11
- package/dist/index.js +41 -34
- package/package.json +47 -47
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 });
|
|
@@ -48,6 +35,7 @@ __export(src_exports, {
|
|
|
48
35
|
createStaticStore: () => createStaticStore,
|
|
49
36
|
createTrigger: () => createTrigger,
|
|
50
37
|
createTriggerCache: () => createTriggerCache,
|
|
38
|
+
createWeakTriggerCache: () => createWeakTriggerCache,
|
|
51
39
|
entries: () => entries,
|
|
52
40
|
forEachEntry: () => forEachEntry,
|
|
53
41
|
handleDiffArray: () => handleDiffArray,
|
|
@@ -145,29 +133,42 @@ function createProxy(traps) {
|
|
|
145
133
|
}
|
|
146
134
|
});
|
|
147
135
|
}
|
|
148
|
-
|
|
149
|
-
|
|
136
|
+
var createTrigger = isDev ? () => (0, import_solid_js.createSignal)(void 0, { equals: false, name: "trigger" }) : () => (0, import_solid_js.createSignal)(void 0, { equals: false });
|
|
137
|
+
function dirtyTriggerCache(key) {
|
|
138
|
+
const trigger = this.get(key);
|
|
139
|
+
if (trigger)
|
|
140
|
+
trigger[1]();
|
|
141
|
+
}
|
|
142
|
+
function dirtyAllTriggerCache() {
|
|
143
|
+
this.forEach((s) => s[1]());
|
|
144
|
+
}
|
|
145
|
+
function trackTriggerCache(key) {
|
|
146
|
+
if (!(0, import_solid_js.getListener)())
|
|
147
|
+
return;
|
|
148
|
+
let trigger = this.get(key);
|
|
149
|
+
if (!trigger) {
|
|
150
|
+
trigger = createTrigger();
|
|
151
|
+
this.set(key, trigger);
|
|
152
|
+
}
|
|
153
|
+
trigger[0]();
|
|
150
154
|
}
|
|
151
|
-
function createTriggerCache(
|
|
155
|
+
function createTriggerCache() {
|
|
152
156
|
const cache = /* @__PURE__ */ new Map();
|
|
153
157
|
return {
|
|
154
|
-
dirty: (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
trigger[0]();
|
|
166
|
-
}
|
|
158
|
+
dirty: dirtyTriggerCache.bind(cache),
|
|
159
|
+
dirtyAll: dirtyAllTriggerCache.bind(cache),
|
|
160
|
+
track: trackTriggerCache.bind(cache)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function createWeakTriggerCache() {
|
|
164
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
165
|
+
return {
|
|
166
|
+
dirty: dirtyTriggerCache.bind(cache),
|
|
167
|
+
track: trackTriggerCache.bind(cache)
|
|
167
168
|
};
|
|
168
169
|
}
|
|
169
170
|
function createStaticStore(init) {
|
|
170
|
-
const copy =
|
|
171
|
+
const copy = { ...init };
|
|
171
172
|
const store = {};
|
|
172
173
|
const cache = /* @__PURE__ */ new Map();
|
|
173
174
|
const getValue = (key) => {
|
|
@@ -256,6 +257,7 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
|
|
|
256
257
|
createStaticStore,
|
|
257
258
|
createTrigger,
|
|
258
259
|
createTriggerCache,
|
|
260
|
+
createWeakTriggerCache,
|
|
259
261
|
entries,
|
|
260
262
|
forEachEntry,
|
|
261
263
|
handleDiffArray,
|
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;
|
|
@@ -219,6 +212,7 @@ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
|
|
|
219
212
|
get: <K extends keyof T>(key: K) => T[K];
|
|
220
213
|
set?: undefined;
|
|
221
214
|
}): Readonly<T>;
|
|
215
|
+
declare type Trigger = [track: VoidFunction, dirty: VoidFunction];
|
|
222
216
|
/**
|
|
223
217
|
* Set listeners in reactive computations and then trigger them when you want.
|
|
224
218
|
* @returns `[track function, dirty function]`
|
|
@@ -231,7 +225,12 @@ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
|
|
|
231
225
|
* // later
|
|
232
226
|
* dirty()
|
|
233
227
|
*/
|
|
234
|
-
declare
|
|
228
|
+
declare const createTrigger: () => Trigger;
|
|
229
|
+
declare type TriggerCache<T> = {
|
|
230
|
+
track: (v: T) => void;
|
|
231
|
+
dirty: (v: T) => void;
|
|
232
|
+
dirtyAll: VoidFunction;
|
|
233
|
+
};
|
|
235
234
|
/**
|
|
236
235
|
* Set listeners in reactive computations and then trigger them when you want. Cache trackers by a `key`.
|
|
237
236
|
* @returns `{ track, dirty, dirtyAll }` functions
|
|
@@ -247,14 +246,34 @@ declare function createTrigger(options?: BaseOptions): Trigger;
|
|
|
247
246
|
* // this won't cause an update:
|
|
248
247
|
* dirty(2)
|
|
249
248
|
*/
|
|
250
|
-
declare function createTriggerCache<T>(
|
|
249
|
+
declare function createTriggerCache<T>(): TriggerCache<T>;
|
|
250
|
+
declare type WeakTriggerCache<T extends object> = {
|
|
251
|
+
track: (v: T) => void;
|
|
252
|
+
dirty: (v: T) => void;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Set listeners in reactive computations and then trigger them when you want. Cache trackers by a `key`.
|
|
256
|
+
* @returns `{ track, dirty }` functions
|
|
257
|
+
* `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.
|
|
258
|
+
* @example
|
|
259
|
+
* const { track, dirty } = createWeakTriggerCache()
|
|
260
|
+
* createEffect(() => {
|
|
261
|
+
* track(1)
|
|
262
|
+
* ...
|
|
263
|
+
* })
|
|
264
|
+
* // later
|
|
265
|
+
* dirty(1)
|
|
266
|
+
* // this won't cause an update:
|
|
267
|
+
* dirty(2)
|
|
268
|
+
*/
|
|
269
|
+
declare function createWeakTriggerCache<T extends object>(): WeakTriggerCache<T>;
|
|
251
270
|
declare type StaticStoreSetter<T extends Readonly<AnyStatic>> = {
|
|
252
271
|
(setter: (prev: T) => Partial<T>): T;
|
|
253
272
|
(state: Partial<T>): T;
|
|
254
273
|
<K extends keyof T>(key: K, state: SetterValue<T[K]>): T;
|
|
255
274
|
};
|
|
256
275
|
/**
|
|
257
|
-
* A shallowly wrapped reactive store object. It behaves similarly to the
|
|
276
|
+
* 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.
|
|
258
277
|
* @param init initial value of the store
|
|
259
278
|
* @returns
|
|
260
279
|
* ```ts
|
|
@@ -272,4 +291,4 @@ declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [acc
|
|
|
272
291
|
*/
|
|
273
292
|
declare function handleDiffArray<T>(current: T[], prev: T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
|
|
274
293
|
|
|
275
|
-
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, arrayEquals, 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 };
|
|
294
|
+
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, promiseTimeout, raceTimeout, warn, withAccess };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
"use strict";
|
|
17
2
|
|
|
18
3
|
// src/index.ts
|
|
19
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getOwner,
|
|
6
|
+
onCleanup,
|
|
7
|
+
createSignal,
|
|
8
|
+
DEV,
|
|
9
|
+
untrack,
|
|
10
|
+
batch,
|
|
11
|
+
getListener
|
|
12
|
+
} from "solid-js";
|
|
20
13
|
import { isServer as _isServer } from "solid-js/web";
|
|
21
14
|
var noop = () => void 0;
|
|
22
15
|
var isServer = _isServer;
|
|
@@ -95,29 +88,42 @@ function createProxy(traps) {
|
|
|
95
88
|
}
|
|
96
89
|
});
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
var createTrigger = isDev ? () => createSignal(void 0, { equals: false, name: "trigger" }) : () => createSignal(void 0, { equals: false });
|
|
92
|
+
function dirtyTriggerCache(key) {
|
|
93
|
+
const trigger = this.get(key);
|
|
94
|
+
if (trigger)
|
|
95
|
+
trigger[1]();
|
|
96
|
+
}
|
|
97
|
+
function dirtyAllTriggerCache() {
|
|
98
|
+
this.forEach((s) => s[1]());
|
|
99
|
+
}
|
|
100
|
+
function trackTriggerCache(key) {
|
|
101
|
+
if (!getListener())
|
|
102
|
+
return;
|
|
103
|
+
let trigger = this.get(key);
|
|
104
|
+
if (!trigger) {
|
|
105
|
+
trigger = createTrigger();
|
|
106
|
+
this.set(key, trigger);
|
|
107
|
+
}
|
|
108
|
+
trigger[0]();
|
|
100
109
|
}
|
|
101
|
-
function createTriggerCache(
|
|
110
|
+
function createTriggerCache() {
|
|
102
111
|
const cache = /* @__PURE__ */ new Map();
|
|
103
112
|
return {
|
|
104
|
-
dirty: (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
trigger[0]();
|
|
116
|
-
}
|
|
113
|
+
dirty: dirtyTriggerCache.bind(cache),
|
|
114
|
+
dirtyAll: dirtyAllTriggerCache.bind(cache),
|
|
115
|
+
track: trackTriggerCache.bind(cache)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function createWeakTriggerCache() {
|
|
119
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
120
|
+
return {
|
|
121
|
+
dirty: dirtyTriggerCache.bind(cache),
|
|
122
|
+
track: trackTriggerCache.bind(cache)
|
|
117
123
|
};
|
|
118
124
|
}
|
|
119
125
|
function createStaticStore(init) {
|
|
120
|
-
const copy =
|
|
126
|
+
const copy = { ...init };
|
|
121
127
|
const store = {};
|
|
122
128
|
const cache = /* @__PURE__ */ new Map();
|
|
123
129
|
const getValue = (key) => {
|
|
@@ -205,6 +211,7 @@ export {
|
|
|
205
211
|
createStaticStore,
|
|
206
212
|
createTrigger,
|
|
207
213
|
createTriggerCache,
|
|
214
|
+
createWeakTriggerCache,
|
|
208
215
|
entries,
|
|
209
216
|
forEachEntry,
|
|
210
217
|
handleDiffArray,
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "2.
|
|
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.
|
|
38
|
-
"solid-register": "^0.2.5",
|
|
39
|
-
"tslib": "^2.
|
|
40
|
-
"tsup": "^
|
|
41
|
-
"uvu": "^0.5.
|
|
42
|
-
"watchlist": "^0.3.1"
|
|
43
|
-
},
|
|
44
|
-
"peerDependencies": {
|
|
45
|
-
"solid-js": "^1.4.1"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@solid-primitives/utils",
|
|
3
|
+
"version": "2.2.1",
|
|
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.7.1",
|
|
38
|
+
"solid-register": "^0.2.5",
|
|
39
|
+
"tslib": "^2.4.0",
|
|
40
|
+
"tsup": "^6.1.2",
|
|
41
|
+
"uvu": "^0.5.4",
|
|
42
|
+
"watchlist": "^0.3.1"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"solid-js": "^1.4.1"
|
|
46
|
+
}
|
|
47
|
+
}
|