@solid-primitives/utils 2.0.1 → 2.1.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 +36 -2
- package/dist/index.d.ts +15 -3
- package/dist/index.js +34 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -49,11 +49,12 @@ __export(src_exports, {
|
|
|
49
49
|
createTriggerCache: () => createTriggerCache,
|
|
50
50
|
entries: () => entries,
|
|
51
51
|
forEachEntry: () => forEachEntry,
|
|
52
|
+
handleDiffArray: () => handleDiffArray,
|
|
52
53
|
isClient: () => isClient,
|
|
53
54
|
isDev: () => isDev,
|
|
54
55
|
isObject: () => isObject,
|
|
55
56
|
isProd: () => isProd,
|
|
56
|
-
isServer: () =>
|
|
57
|
+
isServer: () => isServer,
|
|
57
58
|
keys: () => keys,
|
|
58
59
|
noop: () => noop,
|
|
59
60
|
ofClass: () => ofClass,
|
|
@@ -67,7 +68,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
67
68
|
var import_solid_js = require("solid-js");
|
|
68
69
|
var import_web = require("solid-js/web");
|
|
69
70
|
var noop = () => void 0;
|
|
70
|
-
var
|
|
71
|
+
var isServer = import_web.isServer;
|
|
72
|
+
var isClient = !isServer;
|
|
71
73
|
var isDev = import_solid_js.DEV && isClient;
|
|
72
74
|
var isProd = !isDev;
|
|
73
75
|
var warn = (...a) => isDev && console.warn(...a);
|
|
@@ -204,6 +206,37 @@ function createStaticStore(init) {
|
|
|
204
206
|
};
|
|
205
207
|
return [store, setter];
|
|
206
208
|
}
|
|
209
|
+
function handleDiffArray(current, prev, handleAdded, handleRemoved) {
|
|
210
|
+
const currLength = current.length;
|
|
211
|
+
const prevLength = prev.length;
|
|
212
|
+
let i = 0;
|
|
213
|
+
if (!prevLength) {
|
|
214
|
+
for (; i < currLength; i++)
|
|
215
|
+
handleAdded(current[i]);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!currLength) {
|
|
219
|
+
for (; i < prevLength; i++)
|
|
220
|
+
handleRemoved(prev[i]);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
for (; i < prevLength; i++) {
|
|
224
|
+
if (prev[i] !== current[i])
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
let prevEl;
|
|
228
|
+
let currEl;
|
|
229
|
+
prev = prev.slice(i);
|
|
230
|
+
current = current.slice(i);
|
|
231
|
+
for (prevEl of prev) {
|
|
232
|
+
if (!current.includes(prevEl))
|
|
233
|
+
handleRemoved(prevEl);
|
|
234
|
+
}
|
|
235
|
+
for (currEl of current) {
|
|
236
|
+
if (!prev.includes(currEl))
|
|
237
|
+
handleAdded(currEl);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
207
240
|
// Annotate the CommonJS export names for ESM import in node:
|
|
208
241
|
0 && (module.exports = {
|
|
209
242
|
access,
|
|
@@ -222,6 +255,7 @@ function createStaticStore(init) {
|
|
|
222
255
|
createTriggerCache,
|
|
223
256
|
entries,
|
|
224
257
|
forEachEntry,
|
|
258
|
+
handleDiffArray,
|
|
225
259
|
isClient,
|
|
226
260
|
isDev,
|
|
227
261
|
isObject,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Accessor, Setter, onCleanup } from 'solid-js';
|
|
2
2
|
import { BaseOptions } from 'solid-js/types/reactive/signal';
|
|
3
|
-
export { isServer } from 'solid-js/web';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Can be single or in an array
|
|
@@ -54,6 +53,10 @@ declare type NonIterable<T> = T & {
|
|
|
54
53
|
declare type Definite<T> = {
|
|
55
54
|
[K in keyof T]-?: T[K];
|
|
56
55
|
};
|
|
56
|
+
/** An opposite of `Readonly`. Makes all the params mutable. */
|
|
57
|
+
declare type Mutable<T> = {
|
|
58
|
+
-readonly [K in keyof T]: T[K];
|
|
59
|
+
};
|
|
57
60
|
/** Unwraps the type definition of an object, making it more readable */
|
|
58
61
|
declare type Simplify<T> = T extends object ? {
|
|
59
62
|
[K in keyof T]: T[K];
|
|
@@ -92,8 +95,8 @@ declare type Position = {
|
|
|
92
95
|
|
|
93
96
|
/** no operation */
|
|
94
97
|
declare const noop: Noop;
|
|
98
|
+
declare const isServer: boolean;
|
|
95
99
|
declare const isClient = true;
|
|
96
|
-
|
|
97
100
|
/** development environment */
|
|
98
101
|
declare const isDev = true;
|
|
99
102
|
/** production environment */
|
|
@@ -255,5 +258,14 @@ declare type StaticStoreSetter<T extends Readonly<AnyStatic>> = {
|
|
|
255
258
|
* ```
|
|
256
259
|
*/
|
|
257
260
|
declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [access: T, write: StaticStoreSetter<T>];
|
|
261
|
+
/**
|
|
262
|
+
* Handle items removed and added to the array by diffing it by refference.
|
|
263
|
+
*
|
|
264
|
+
* @param current new array instance
|
|
265
|
+
* @param prev previous array copy
|
|
266
|
+
* @param handleAdded called once for every added item to array
|
|
267
|
+
* @param handleRemoved called once for every removed from array
|
|
268
|
+
*/
|
|
269
|
+
declare function handleDiffArray<T>(current: T[], prev: T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
|
|
258
270
|
|
|
259
|
-
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, 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, isClient, isDev, isObject, isProd, keys, noop, ofClass, onRootCleanup, promiseTimeout, raceTimeout, warn, withAccess };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -17,8 +17,9 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
|
|
18
18
|
// src/index.ts
|
|
19
19
|
import { getOwner, onCleanup, createSignal, DEV, untrack, batch } from "solid-js";
|
|
20
|
-
import { isServer } from "solid-js/web";
|
|
20
|
+
import { isServer as _isServer } from "solid-js/web";
|
|
21
21
|
var noop = () => void 0;
|
|
22
|
+
var isServer = _isServer;
|
|
22
23
|
var isClient = !isServer;
|
|
23
24
|
var isDev = DEV && isClient;
|
|
24
25
|
var isProd = !isDev;
|
|
@@ -156,6 +157,37 @@ function createStaticStore(init) {
|
|
|
156
157
|
};
|
|
157
158
|
return [store, setter];
|
|
158
159
|
}
|
|
160
|
+
function handleDiffArray(current, prev, handleAdded, handleRemoved) {
|
|
161
|
+
const currLength = current.length;
|
|
162
|
+
const prevLength = prev.length;
|
|
163
|
+
let i = 0;
|
|
164
|
+
if (!prevLength) {
|
|
165
|
+
for (; i < currLength; i++)
|
|
166
|
+
handleAdded(current[i]);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (!currLength) {
|
|
170
|
+
for (; i < prevLength; i++)
|
|
171
|
+
handleRemoved(prev[i]);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
for (; i < prevLength; i++) {
|
|
175
|
+
if (prev[i] !== current[i])
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
let prevEl;
|
|
179
|
+
let currEl;
|
|
180
|
+
prev = prev.slice(i);
|
|
181
|
+
current = current.slice(i);
|
|
182
|
+
for (prevEl of prev) {
|
|
183
|
+
if (!current.includes(prevEl))
|
|
184
|
+
handleRemoved(prevEl);
|
|
185
|
+
}
|
|
186
|
+
for (currEl of current) {
|
|
187
|
+
if (!prev.includes(currEl))
|
|
188
|
+
handleAdded(currEl);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
159
191
|
export {
|
|
160
192
|
access,
|
|
161
193
|
accessArray,
|
|
@@ -173,6 +205,7 @@ export {
|
|
|
173
205
|
createTriggerCache,
|
|
174
206
|
entries,
|
|
175
207
|
forEachEntry,
|
|
208
|
+
handleDiffArray,
|
|
176
209
|
isClient,
|
|
177
210
|
isDev,
|
|
178
211
|
isObject,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.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",
|