Skip to content

StoreStack

Alexandre Moreau-Lemay edited this page Aug 22, 2022 · 4 revisions
import { StoreStack } from "https://deno.land/x/fresh_store@v1.0.1/mod.ts";

A multi Store container.

Implementation

class StoreStack {
    public addStore(newItem: AnyStore): Pointer;
    public addStoreAtPointer(
        newItem: AnyStore,
        pointer: Pointer,
        options?: {
            override?: boolean;
            verbose?: boolean;
        },
    ): void;
    public get<T = any>(ptr: Pointer): Store<T> | undefined;
    public removeStore(ptr: Pointer, options?: {
        verbose?: boolean;
    }): void;
    public upsert<T>(
        defaultValue: T,
        pointer: Pointer,
        ...observers: Observer<T>[],
    ): void;
 
    static configure(): void;
}

Static Methods

Configure

configure(): void

Checks if the StoreStack is instantiated on window.stores and creates it if it's not.

Methods

addStore

addStore(newItem: AnyStore): Pointer

Adds a store to the memory stack and assigns it a pointer.

Parameters

  1. newItem: AnyStore

The Store to be added to the stack.


addStoreAtPointer

addStoreAtPointer(newItem: AnyStore, pointer: Pointer, options?: {override?: boolean;verbose?: boolean;}): void

Adds a Store to the specified Pointer. If a store already exists at the address, an option can be passed to override it. If overrideis set to false, but the verbose option is set to true, and the memory is already allocated, the store will NOT be overriden, and a message will output to the console.

Parameters

  1. newItem: AnyStore

The Store to be added to the stack.

  1. pointer: Pointer

The Pointer to the memory address where the store should be inserted.

  1. options?: { override?: boolean, verbose?: boolean } (Optional)

Defines if a store should be overrided if it exists at the Pointer and if a verbose error should be logged to the console if override is set to false.

Throws

  1. MemoryAllocationError

If the address is already allocated and override isn't set to true. See MemoryAllocationError.

Clone this wiki locally