-
Notifications
You must be signed in to change notification settings - Fork 0
StoreStack
import { StoreStack } from "https://deno.land/x/fresh_store@v1.0.1/mod.ts";A multi Store container.
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;
}configure(): voidChecks if the StoreStack is instantiated on window.stores and creates it if it's not.
addStore(newItem: AnyStore): PointerAdds a store to the memory stack and assigns it a pointer.
newItem: AnyStore
The
Storeto be added to the stack.
addStoreAtPointer(newItem: AnyStore, pointer: Pointer, options?: {override?: boolean;verbose?: boolean;}): voidAdds 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.
newItem: AnyStore
The
Storeto be added to the stack.
pointer: Pointer
The
Pointerto the memory address where the store should be inserted.
-
options?: { override?: boolean, verbose?: boolean }(Optional)
Defines if a store should be overrided if it exists at the
Pointerand if a verbose error should be logged to the console ifoverrideis set to false.
MemoryAllocationError
If the address is already allocated and
overrideisn't set totrue. SeeMemoryAllocationError.
get<T = any>(ptr: Pointer): Store<T> | undefinedReturns a reference to the store at the address if it exists, otherwise undefined. A type can be passed in order to make the return value typed.
const ptr = useStore(0);
console.log(Stores.get<number>(ptr).state); // Output: 0ptr: Pointer
The
Pointerto theStore.
The Store, if it exists.
removeStore(ptr: Pointer, options?: {verbose?: boolean;}): voidRemoves a Store from the memory stack. If the Pointer points to unallocated memory, it will throw an error and output a message to the console if the verbose option is set to true.
ptr: Pointer
The
Pointerto the memory location of theStore.
-
options?: {verbose?: boolean;}(Optional)
If the removal fails, should the function output it to the console? Defaults to
false
NullPointerError
If attempting to delete a
Storeat unallocated memory location. SeeNullPointerError.