Skip to content

Commit d679bf3

Browse files
committed
Fix event bugs
1 parent 736c932 commit d679bf3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Store.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class Store {
2020
}
2121

2222
_path(path, create = true) {
23-
if (!Array.isArray(path) || !path.length || path.length > this.#path.length + 1) {
24-
throw new Error(`Path length must be between 1 and ${this.#path.length + 1}`);
23+
if (!Array.isArray(path) || !path.length) {
24+
throw new Error(`Path length cannot be 0`);
2525
}
2626
/*
2727
base -> {
@@ -36,10 +36,7 @@ export class Store {
3636
}
3737
*/
3838
return path.reduce((node, key, i) => {
39-
if (create === 0 && i && !node.subtree.has(key)) {
40-
return node;
41-
}
42-
if (create && !node.subtree.has(key)) {
39+
if (create && !node?.subtree.has(key)) {
4340
const subtree = new Map;
4441
const entries = new Set;
4542
const dispose = () => {
@@ -50,6 +47,9 @@ export class Store {
5047
};
5148
node.subtree.set(key, { subtree, entries, context: node, dispose });
5249
}
50+
if (create === 0 && i && !node?.subtree.has(key)) {
51+
return node;
52+
}
5353
return node?.subtree.get(key);
5454
}, { subtree: this.#registry });
5555
}

0 commit comments

Comments
 (0)