@isoftdata/svelte-store-crud
Advanced tools
@@ -9,2 +9,3 @@ import type { ConditionalKeys, Simplify } from 'type-fest'; | ||
| export type CrudMap<T> = Record<CrudMapKey, EntityMap<T>>; | ||
| type ArrayCrudMap<T> = Record<CrudMapKey, Array<T>>; | ||
| /** Creates a new CRUD Map, without the rest of the store logic */ | ||
@@ -51,3 +52,4 @@ export declare const newCrudMap: <T>() => CrudMap<T>; | ||
| constructor(idKey: K); | ||
| set(value: CrudMap<T> | MapCrudMap<T>): void; | ||
| set(value: CrudMap<T> | MapCrudMap<T> | ArrayCrudMap<T>): void; | ||
| static getValuesForSet<T>(values: EntityMap<T> | Map<EntityIdValue<T>, T> | Array<T>): Array<T>; | ||
| create(entity: T | T[]): void; | ||
@@ -54,0 +56,0 @@ update(entity: T | T[]): void; |
+12
-3
@@ -152,6 +152,15 @@ import { writable } from 'svelte/store'; | ||
| this.clear(); | ||
| this.create(value.created instanceof Map ? Array.from(value.created.values()) : Object.values(value.created)); | ||
| this.update(value.updated instanceof Map ? Array.from(value.updated.values()) : Object.values(value.updated)); | ||
| this.delete(value.deleted instanceof Map ? Array.from(value.deleted.values()) : Object.values(value.deleted)); | ||
| this.create(CrudRuneStore.getValuesForSet(value.created)); | ||
| this.update(CrudRuneStore.getValuesForSet(value.updated)); | ||
| this.delete(CrudRuneStore.getValuesForSet(value.deleted)); | ||
| } | ||
| static getValuesForSet(values) { | ||
| if (values instanceof Map) { | ||
| return Array.from(values.values()); | ||
| } | ||
| else if (Array.isArray(values)) { | ||
| return values; | ||
| } | ||
| return Object.values(values); | ||
| } | ||
| create(entity) { | ||
@@ -158,0 +167,0 @@ this.#updateEntity(entity, 'created'); |
+1
-1
| { | ||
| "name": "@isoftdata/svelte-store-crud", | ||
| "version": "2.4.0", | ||
| "version": "2.5.0", | ||
| "files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
18102
1.52%314
3.63%