Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Store<T> implements Subject<T> {
* @remarks
* To mutate the state, use {@link Store.set}.
*/
public get state(): T { return structuredClone(this.#state) as T; }
public get state(): T { return this.#state; }

/**
* Convenience method to create a unique pointer.
Expand Down Expand Up @@ -169,9 +169,9 @@ export class Store<T> implements Subject<T> {
*/
public set(options: T | ((prevState: T) => T)): void {
if (typeof options === "function") {
this.#state = structuredClone((options as (prevState: T) => T)(structuredClone(this.state) as T)) as T;
this.#state = (options as (prevState: T) => T)(this.#state);
} else {
this.#state = structuredClone(options) as T;
this.#state = options;
}

this.notify();
Expand Down