We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0e2440a commit 6bd87b9Copy full SHA for 6bd87b9
1 file changed
mod.ts
@@ -1,5 +1,11 @@
1
/// <reference path="./global.d.ts" />
2
3
+let clone = structuredClone;
4
+
5
+if ('clone' in window === false) {
6
+ clone = (await import('https://esm.sh/lodash-es@4.17.21')).cloneDeep;
7
+}
8
9
export interface Observer<T> {
10
update(subject: Store<T>): void;
11
}
@@ -43,9 +49,9 @@ export class Store<T> implements Subject<T> {
43
49
44
50
public set(options: T | ((prevState: T) => T)): void {
45
51
if (typeof options === "function") {
46
- this.state = (options as (prevState: T) => T)(structuredClone(this.state) as T);
52
+ this.state = (options as (prevState: T) => T)(clone(this.state) as T);
47
53
} else {
48
- this.state = structuredClone(options) as T;
54
+ this.state = clone(options) as T;
55
56
57
this.notify();
0 commit comments