@solid-primitives/immutable
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -29,4 +29,4 @@ import { Accessor } from 'solid-js'; | ||
*/ | ||
declare function createImmutable<T extends ImmutableObject | ImmutableArray>(source: Accessor<T>, options?: ReconcileOptions): T; | ||
declare function createImmutable<T extends object>(source: Accessor<T>, options?: ReconcileOptions): T; | ||
export { ImmutableArray, ImmutableObject, ImmutablePrimitive, ImmutableValue, createImmutable }; |
@@ -81,3 +81,2 @@ import { createMemo, untrack, $PROXY, $TRACK, runWithOwner, getOwner, onCleanup, createRoot, getListener } from 'solid-js'; | ||
}; | ||
var getArrayItemKey = (item, index, { key, merge }) => isWrappable(item) && key in item ? item[key] : merge ? index : item; | ||
var ArrayTraps = class extends CommonTraps { | ||
@@ -91,3 +90,3 @@ #trackLength; | ||
source, | ||
(item, index) => getArrayItemKey(item, index, config), | ||
(item, index) => isWrappable(item) ? config.key in item ? item[config.key] : config.merge ? index : item : index, | ||
(item) => new PropertyWrapper(item, getOwner(), config) | ||
@@ -100,3 +99,3 @@ ), | ||
} | ||
get(target, property, receiver) { | ||
get(_, property, receiver) { | ||
if (property === $RAW) | ||
@@ -116,11 +115,8 @@ return untrack(this.s); | ||
return Array.prototype[property].bind(receiver); | ||
if (typeof property === "string") { | ||
const num = Number(property); | ||
if (isNaN(num)) | ||
return this.s()[property]; | ||
property = num; | ||
} | ||
if (property >= untrack(this.#trackLength)) | ||
return this.#trackLength(), this.s()[property]; | ||
return untrack(this.#trackItems)[property]?.get(); | ||
const num = typeof property === "string" ? parseInt(property) : property; | ||
if (!Number.isInteger(num) || num < 0) | ||
return this.s()[property]; | ||
if (num >= untrack(this.#trackLength)) | ||
return this.#trackLength(), this.s()[num]; | ||
return untrack(this.#trackItems)[num]?.get(); | ||
} | ||
@@ -127,0 +123,0 @@ }; |
{ | ||
"name": "@solid-primitives/immutable", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Primitive for rectifying immutable values and dealing with immutability in Solid.", | ||
@@ -5,0 +5,0 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27474
529