@solid-primitives/range
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -53,5 +53,5 @@ import { onCleanup, createMemo, untrack, createRoot, createSignal } from 'solid-js'; | ||
return untrack(() => { | ||
const items2 = mapLength(len); | ||
const newItems = mapLength(len); | ||
prevLen = len; | ||
return items2; | ||
return newItems; | ||
}); | ||
@@ -66,11 +66,11 @@ }; | ||
} | ||
function mapRange(start, to, step, mapFn, options = {}) { | ||
let disposers = [], items = [], prevStart = 0, prevTo = 0, prevStep = step(), fallback = false; | ||
function mapRange(getStart, getTo, getStep, mapFn, options = {}) { | ||
let disposers = [], items = [], prevStart = 0, prevTo = 0, prevStep = getStep(), fallback = false; | ||
onCleanup(() => disposers.forEach((f) => f())); | ||
const mapper = (i, n, items2, disposers2) => createRoot((dispose) => { | ||
disposers2[i] = dispose; | ||
items2[i] = mapFn(n); | ||
const mapper = (i, n, itemsList, disposersList) => createRoot((dispose) => { | ||
disposersList[i] = dispose; | ||
itemsList[i] = mapFn(n); | ||
}); | ||
const mapNewRange = (start2, to2, step2) => { | ||
if (start2 === to2) { | ||
const mapNewRange = (start, to, step) => { | ||
if (start === to) { | ||
disposers.forEach((f) => f()); | ||
@@ -87,3 +87,3 @@ if (options.fallback) { | ||
} | ||
let n = start2, i = 0; | ||
let n = start, i = 0; | ||
if (fallback) { | ||
@@ -95,7 +95,7 @@ fallback = false; | ||
if (!items.length) { | ||
for (; n < to2; i++, n += step2) | ||
for (; n < to; i++, n += step) | ||
mapper(i, n, items, disposers); | ||
return items; | ||
} | ||
const newLength = ceil((to2 - start2) / step2); | ||
const newLength = ceil((to - start) / step); | ||
const newItems = new Array(newLength); | ||
@@ -105,9 +105,9 @@ const newDisposers = new Array(newLength); | ||
let end; | ||
if (start2 < prevStart) { | ||
end = min(ceil((prevStart - start2) / step2), newLength); | ||
for (n = start2; i < end; i++, n += step2) | ||
if (start < prevStart) { | ||
end = min(ceil((prevStart - start) / step), newLength); | ||
for (n = start; i < end; i++, n += step) | ||
mapper(i, n, newItems, newDisposers); | ||
} | ||
end = ceil((min(prevTo, to2) - start2) / step2); | ||
for (; i < end; n += step2, i++) { | ||
end = ceil((min(prevTo, to) - start) / step); | ||
for (; i < end; n += step, i++) { | ||
let index = (n - prevStart) / prevStep; | ||
@@ -123,4 +123,4 @@ if (Number.isInteger(index) || index < 1 && index + Number.EPSILON > 1) { | ||
} | ||
if (to2 > prevTo) { | ||
for (; i < newLength; i++, n += step2) | ||
if (to > prevTo) { | ||
for (; i < newLength; i++, n += step) | ||
mapper(i, n, newItems, newDisposers); | ||
@@ -133,3 +133,3 @@ } | ||
return () => { | ||
let _step = step(); | ||
let _step = getStep(); | ||
if (_step === 0) { | ||
@@ -139,8 +139,8 @@ console.warn("Range cannot have a step of 0"); | ||
} | ||
let _start = start(); | ||
let _to = to(); | ||
let _start = getStart(); | ||
let _to = getTo(); | ||
_step = abs(_step); | ||
const positive = _start <= _to; | ||
if (!positive) { | ||
let temp = _start; | ||
const temp = _start; | ||
const x = (_start - _to) / _step; | ||
@@ -172,3 +172,3 @@ _start = _start - (Number.isInteger(x) ? x - 1 : floor(x)) * _step; | ||
} | ||
function indexRange(start, to, step, mapFn, options = {}) { | ||
function indexRange(getStart, getTo, getStep, mapFn, options = {}) { | ||
let disposers = [], items = [], setters = [], fallback = false; | ||
@@ -182,4 +182,4 @@ onCleanup(() => disposers.forEach((f) => f())); | ||
}); | ||
const mapNewRange = (start2, to2, step2) => { | ||
const newLength = abs(ceil((to2 - start2) / step2)); | ||
const mapNewRange = (start, to, step) => { | ||
const newLength = abs(ceil((to - start) / step)); | ||
if (newLength === 0) { | ||
@@ -198,3 +198,3 @@ disposers.forEach((f) => f()); | ||
} | ||
let n = start2, i = 0; | ||
let n = start, i = 0; | ||
if (fallback) { | ||
@@ -207,3 +207,3 @@ fallback = false; | ||
if (!oldLength) { | ||
for (; i < newLength; i++, n += step2) | ||
for (; i < newLength; i++, n += step) | ||
mapper(i, n); | ||
@@ -213,5 +213,5 @@ return items; | ||
const bodyEnd = min(newLength, oldLength); | ||
for (; i < bodyEnd; i++, n += step2) | ||
for (; i < bodyEnd; i++, n += step) | ||
setters[i](n); | ||
for (; i < newLength; i++, n += step2) | ||
for (; i < newLength; i++, n += step) | ||
mapper(i, n); | ||
@@ -226,3 +226,3 @@ if (newLength < oldLength) { | ||
return () => { | ||
let _step = step(); | ||
let _step = getStep(); | ||
if (_step === 0) { | ||
@@ -232,4 +232,4 @@ console.warn("Range cannot have a step of 0"); | ||
} | ||
let _start = start(); | ||
let _to = to(); | ||
const _start = getStart(); | ||
const _to = getTo(); | ||
_step = abs(_step) * sign(_to - _start || 1); | ||
@@ -236,0 +236,0 @@ return untrack(mapNewRange.bind(void 0, _start, _to, _step)); |
@@ -51,5 +51,5 @@ import { MaybeAccessor } from '@solid-primitives/utils'; | ||
* Reactively maps a number range of specified `stop`, `to` and `step`, with a callback function - underlying helper for the `<Range>` control flow. | ||
* @param start number accessor of the start of the range | ||
* @param to number accessor of the end of the range *(not included in the range)* | ||
* @param step number accessor of the difference between two points in the range *(negative step value depends on the `to` being greater/smaller than `start`, not this argument)* | ||
* @param getStart number accessor of the start of the range | ||
* @param getTo number accessor of the end of the range *(not included in the range)* | ||
* @param getStep number accessor of the difference between two points in the range *(negative step value depends on the `to` being greater/smaller than `start`, not this argument)* | ||
* @param mapFn reactive function used to create mapped output item array | ||
@@ -71,3 +71,3 @@ * @param options a fallback for when the input list is empty or missing | ||
*/ | ||
declare function mapRange<T>(start: Accessor<number>, to: Accessor<number>, step: Accessor<number>, mapFn: (n: number) => T, options?: { | ||
declare function mapRange<T>(getStart: Accessor<number>, getTo: Accessor<number>, getStep: Accessor<number>, mapFn: (n: number) => T, options?: { | ||
fallback?: Accessor<T>; | ||
@@ -97,5 +97,5 @@ }): Accessor<T[]>; | ||
* Reactively maps a number range of specified `stop`, `to` and `step`, with a callback function - underlying helper for the `<IndexRange>` control flow. | ||
* @param start number accessor of the start of the range | ||
* @param to number accessor of the end of the range *(not included in the range)* | ||
* @param step number accessor of the difference between two points in the range *(negative step value depends on the `to` being greater/smaller than `start`, not this argument)* | ||
* @param getStart number accessor of the start of the range | ||
* @param getTo number accessor of the end of the range *(not included in the range)* | ||
* @param getStep number accessor of the difference between two points in the range *(negative step value depends on the `to` being greater/smaller than `start`, not this argument)* | ||
* @param mapFn reactive function used to create mapped output item array, number value is available as a signal. | ||
@@ -117,3 +117,3 @@ * @param options a fallback for when the input list is empty or missing | ||
*/ | ||
declare function indexRange<T>(start: Accessor<number>, to: Accessor<number>, step: Accessor<number>, mapFn: (n: Accessor<number>) => T, options?: { | ||
declare function indexRange<T>(getStart: Accessor<number>, getTo: Accessor<number>, getStep: Accessor<number>, mapFn: (n: Accessor<number>) => T, options?: { | ||
fallback?: Accessor<T>; | ||
@@ -120,0 +120,0 @@ }): Accessor<T[]>; |
@@ -53,5 +53,5 @@ import { onCleanup, createMemo, untrack, createRoot, createSignal } from 'solid-js'; | ||
return untrack(() => { | ||
const items2 = mapLength(len); | ||
const newItems = mapLength(len); | ||
prevLen = len; | ||
return items2; | ||
return newItems; | ||
}); | ||
@@ -66,11 +66,11 @@ }; | ||
} | ||
function mapRange(start, to, step, mapFn, options = {}) { | ||
let disposers = [], items = [], prevStart = 0, prevTo = 0, prevStep = step(), fallback = false; | ||
function mapRange(getStart, getTo, getStep, mapFn, options = {}) { | ||
let disposers = [], items = [], prevStart = 0, prevTo = 0, prevStep = getStep(), fallback = false; | ||
onCleanup(() => disposers.forEach((f) => f())); | ||
const mapper = (i, n, items2, disposers2) => createRoot((dispose) => { | ||
disposers2[i] = dispose; | ||
items2[i] = mapFn(n); | ||
const mapper = (i, n, itemsList, disposersList) => createRoot((dispose) => { | ||
disposersList[i] = dispose; | ||
itemsList[i] = mapFn(n); | ||
}); | ||
const mapNewRange = (start2, to2, step2) => { | ||
if (start2 === to2) { | ||
const mapNewRange = (start, to, step) => { | ||
if (start === to) { | ||
disposers.forEach((f) => f()); | ||
@@ -87,3 +87,3 @@ if (options.fallback) { | ||
} | ||
let n = start2, i = 0; | ||
let n = start, i = 0; | ||
if (fallback) { | ||
@@ -95,7 +95,7 @@ fallback = false; | ||
if (!items.length) { | ||
for (; n < to2; i++, n += step2) | ||
for (; n < to; i++, n += step) | ||
mapper(i, n, items, disposers); | ||
return items; | ||
} | ||
const newLength = ceil((to2 - start2) / step2); | ||
const newLength = ceil((to - start) / step); | ||
const newItems = new Array(newLength); | ||
@@ -105,9 +105,9 @@ const newDisposers = new Array(newLength); | ||
let end; | ||
if (start2 < prevStart) { | ||
end = min(ceil((prevStart - start2) / step2), newLength); | ||
for (n = start2; i < end; i++, n += step2) | ||
if (start < prevStart) { | ||
end = min(ceil((prevStart - start) / step), newLength); | ||
for (n = start; i < end; i++, n += step) | ||
mapper(i, n, newItems, newDisposers); | ||
} | ||
end = ceil((min(prevTo, to2) - start2) / step2); | ||
for (; i < end; n += step2, i++) { | ||
end = ceil((min(prevTo, to) - start) / step); | ||
for (; i < end; n += step, i++) { | ||
let index = (n - prevStart) / prevStep; | ||
@@ -123,4 +123,4 @@ if (Number.isInteger(index) || index < 1 && index + Number.EPSILON > 1) { | ||
} | ||
if (to2 > prevTo) { | ||
for (; i < newLength; i++, n += step2) | ||
if (to > prevTo) { | ||
for (; i < newLength; i++, n += step) | ||
mapper(i, n, newItems, newDisposers); | ||
@@ -133,12 +133,12 @@ } | ||
return () => { | ||
let _step = step(); | ||
let _step = getStep(); | ||
if (_step === 0) { | ||
return items; | ||
} | ||
let _start = start(); | ||
let _to = to(); | ||
let _start = getStart(); | ||
let _to = getTo(); | ||
_step = abs(_step); | ||
const positive = _start <= _to; | ||
if (!positive) { | ||
let temp = _start; | ||
const temp = _start; | ||
const x = (_start - _to) / _step; | ||
@@ -170,3 +170,3 @@ _start = _start - (Number.isInteger(x) ? x - 1 : floor(x)) * _step; | ||
} | ||
function indexRange(start, to, step, mapFn, options = {}) { | ||
function indexRange(getStart, getTo, getStep, mapFn, options = {}) { | ||
let disposers = [], items = [], setters = [], fallback = false; | ||
@@ -180,4 +180,4 @@ onCleanup(() => disposers.forEach((f) => f())); | ||
}); | ||
const mapNewRange = (start2, to2, step2) => { | ||
const newLength = abs(ceil((to2 - start2) / step2)); | ||
const mapNewRange = (start, to, step) => { | ||
const newLength = abs(ceil((to - start) / step)); | ||
if (newLength === 0) { | ||
@@ -196,3 +196,3 @@ disposers.forEach((f) => f()); | ||
} | ||
let n = start2, i = 0; | ||
let n = start, i = 0; | ||
if (fallback) { | ||
@@ -205,3 +205,3 @@ fallback = false; | ||
if (!oldLength) { | ||
for (; i < newLength; i++, n += step2) | ||
for (; i < newLength; i++, n += step) | ||
mapper(i, n); | ||
@@ -211,5 +211,5 @@ return items; | ||
const bodyEnd = min(newLength, oldLength); | ||
for (; i < bodyEnd; i++, n += step2) | ||
for (; i < bodyEnd; i++, n += step) | ||
setters[i](n); | ||
for (; i < newLength; i++, n += step2) | ||
for (; i < newLength; i++, n += step) | ||
mapper(i, n); | ||
@@ -224,8 +224,8 @@ if (newLength < oldLength) { | ||
return () => { | ||
let _step = step(); | ||
let _step = getStep(); | ||
if (_step === 0) { | ||
return items; | ||
} | ||
let _start = start(); | ||
let _to = to(); | ||
const _start = getStart(); | ||
const _to = getTo(); | ||
_step = abs(_step) * sign(_to - _start || 1); | ||
@@ -232,0 +232,0 @@ return untrack(mapNewRange.bind(void 0, _start, _to, _step)); |
{ | ||
"name": "@solid-primitives/range", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Control Flow Primitives for displaying given number or a number range of elements.", | ||
@@ -61,6 +61,6 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", | ||
"devDependencies": { | ||
"solid-transition-group": "^0.0.8" | ||
"solid-transition-group": "^0.0.13" | ||
}, | ||
"dependencies": { | ||
"@solid-primitives/utils": "^5.0.0" | ||
"@solid-primitives/utils": "^5.2.1" | ||
}, | ||
@@ -67,0 +67,0 @@ "peerDependencies": { |
@@ -50,3 +50,3 @@ <p> | ||
fallback?: Accessor<T>; | ||
} | ||
}, | ||
): Accessor<T[]>; | ||
@@ -116,3 +116,3 @@ ``` | ||
fallback?: Accessor<T>; | ||
} | ||
}, | ||
): Accessor<T[]>; | ||
@@ -170,3 +170,3 @@ ``` | ||
children: ((number: number) => T) | T; | ||
} | ||
}, | ||
): Accessor<T[]>; | ||
@@ -193,3 +193,3 @@ ``` | ||
return value; | ||
} | ||
}, | ||
); | ||
@@ -210,3 +210,3 @@ mapped(); // => [0, 0.5, 1, 1.5, 2...] | ||
fallback?: Accessor<T>; | ||
} | ||
}, | ||
): Accessor<T[]>; | ||
@@ -264,3 +264,3 @@ ``` | ||
children: ((number: Accessor<number>) => T) | T; | ||
} | ||
}, | ||
): Accessor<T[]>; | ||
@@ -267,0 +267,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47072