function localStorageCollectionOptions<TExplicit, TSchema, TFallback>(config): object
function localStorageCollectionOptions<TExplicit, TSchema, TFallback>(config): object
Definiert in: packages/db/src/local-storage.ts:205
Erstellt localStorage-Sammlungsoptionen zur Verwendung mit einer Standard-Collection
Diese Funktion erstellt eine Collection, die Daten in localStorage/sessionStorage speichert und Änderungen über Browser-Tabs hinweg mithilfe von Storage-Events synchronisiert.
• TExplicit = unknown
Der explizite Typ der Elemente in der Collection (höchste Priorität)
• TSchema erweitert StandardSchemaV1<unknown, unknown> = never
Der Schema-Typ für Validierung und Typableitung (zweite Priorität)
• TFallback erweitert object = Record<string, unknown>
Der Fallback-Typ, wenn kein expliziter Typ oder kein Schema-Typ angegeben wird
LocalStorageCollectionConfig<TExplicit, TSchema, TFallback>
Konfigurationsoptionen für die localStorage-Collection
Objekt
Collection-Optionen mit Utilities, einschließlich clearStorage und getStorageSize
getKey: (item) => string | number;
getKey: (item) => string | number;
string | number
id: string = collectionId;
id: string = collectionId;
onDelete: (params) => Promise<any> = wrappedOnDelete;
onDelete: (params) => Promise<any> = wrappedOnDelete;
DeleteMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Promise<any>
onInsert: (params) => Promise<any> = wrappedOnInsert;
onInsert: (params) => Promise<any> = wrappedOnInsert;
InsertMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Promise<any>
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
UpdateMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>>
Promise<any>
optional schema: TSchema;
optional schema: TSchema;
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number> & object;
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, string | number> & object;
optional manualTrigger: () => void;
optional manualTrigger: () => void;
void
utils: object;
utils: object;
clearStorage: ClearStorageFn;
clearStorage: ClearStorageFn;
getStorageSize: GetStorageSizeFn;
getStorageSize: GetStorageSizeFn;
// Basic localStorage collection
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
})
)
// Basic localStorage collection
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
})
)
// localStorage collection with custom storage
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
storage: window.sessionStorage, // Use sessionStorage instead
getKey: (item) => item.id,
})
)
// localStorage collection with custom storage
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
storage: window.sessionStorage, // Use sessionStorage instead
getKey: (item) => item.id,
})
)
// localStorage collection with mutation handlers
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
},
})
)
// localStorage collection with mutation handlers
const collection = createCollection(
localStorageCollectionOptions({
storageKey: 'todos',
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
},
})
)
Ihre wöchentliche Dosis JavaScript-Nachrichten. Jeden Montag kostenlos an über 100.000 Entwickler geliefert.