Commit 0ab6c08c96392d6f3a76fbaf0a826b48445e56b8
return tree node when setting value
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 3/5/2018, 11:25:29 PM
Parent: 3228beb1ebc4a9921b555fd514ede84f91ce5bf9
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -79,9 +79,9 @@ | ||
79 | 79 … | return {value, root, node, parent, index} |
80 | 80 … | } |
81 | 81 … | |
82 | 82 … | /** |
83 | - * stores a value at a given key | |
83 … | + * stores a value at a given key returning the tree node that the value was saved in | |
84 | 84 … | * @param {*} key |
85 | 85 … | * @return {Promise} |
86 | 86 … | */ |
87 | 87 … | set (key, value) { |
@@ -91,13 +91,15 @@ | ||
91 | 91 … | |
92 | 92 … | async _set (key, value) { |
93 | 93 … | if (treeNode.isEmpty(this.root)) { |
94 | 94 … | this.root['/'] = createNode(key, [null, null], value)['/'] |
95 … | + return this.root['/'] | |
95 | 96 … | } else { |
96 | - let {root, extensionIndex, extension, index, value: rValue} = await this._get(key) | |
97 … | + let {node, root, extensionIndex, extension, index, value: rValue} = await this._get(key) | |
97 | 98 … | |
98 | 99 … | if (rValue) { |
99 | 100 … | treeNode.setValue(root, value) |
101 … | + return node | |
100 | 102 … | } else { |
101 | 103 … | if (extensionIndex !== undefined) { |
102 | 104 … | // split the extension node in two |
103 | 105 … | const extensionKey = extension[extensionIndex] |
@@ -119,17 +121,19 @@ | ||
119 | 121 … | const newNode = createNode(extension, [null, null], value) |
120 | 122 … | const rootBranch = treeNode.getBranch(root) |
121 | 123 … | rootBranch[keySegment] = newNode |
122 | 124 … | treeNode.setBranch(root, rootBranch) |
125 … | + return newNode['/'] | |
123 | 126 … | } else { |
124 | 127 … | treeNode.setValue(root, value) |
128 … | + return root['/'] | |
125 | 129 … | } |
126 | 130 … | } |
127 | 131 … | } |
128 | 132 … | } |
129 | 133 … | |
130 | 134 … | /** |
131 | - * deletes a value at a given key | |
135 … | + *smContainer.js deletes a value at a given key | |
132 | 136 … | * @param {*} key |
133 | 137 … | * @return {Promise} |
134 | 138 … | */ |
135 | 139 … | delete (key) { |
Built with git-ssb-web