Comparing version 0.5.3 to 0.5.4
@@ -1047,2 +1047,41 @@ 'use strict'; | ||
const bindAllDataListener = (branch, persist) => { | ||
if (!branch.listeners.allData) { | ||
branch.listeners.allData = {}; | ||
} | ||
branch.listeners.allData['persist'] = (type, _, item) => { | ||
if (branch.leaves[item.id]) { | ||
if (type === 'remove') { | ||
persist.remove(String(item.id)); | ||
} else { | ||
persist.store( | ||
String(item.id), | ||
Object.assign( | ||
{ keyString: getString(branch.leaves[item.id].key) }, | ||
branch.leaves[item.id] | ||
) | ||
); | ||
} | ||
} | ||
}; | ||
}; | ||
const loadLeaf = (branch, id, leaf) => { | ||
addToStrings(leaf.key, leaf.keyString); | ||
delete leaf.keyString; | ||
if (leaf.val || leaf.rT) { | ||
const rTold = getRtFromLeaves(branch, id); | ||
if (rTold) { | ||
delete branch.rF[rTold][id]; | ||
} | ||
if (leaf.rT) { | ||
addReferenceFrom(branch, id, leaf.rT); | ||
} | ||
} | ||
branch.leaves[id] = leaf; | ||
}; | ||
const cloneIds = (to, from, parent) => { | ||
@@ -1107,4 +1146,6 @@ for (const id in from) { | ||
return persist.start(new Leaf(branch, root), addToStrings, getString) | ||
.then(() => persist.load()) | ||
branch.persist = persist; | ||
return persist.start() | ||
.then(() => persist.load((id, leaf) => loadLeaf(branch, id, leaf))) | ||
.then(() => bindAllDataListener(branch, persist)) | ||
.then(() => setToNewBranch(branch, val, stamp)) | ||
@@ -1111,0 +1152,0 @@ }; |
{ | ||
"name": "stx", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "a blazing fast state manager with network sync out of the box", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
441129
6037