Skip to content

Commit

Permalink
rename clearBranchKeys to fireBranchKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
mstdokumaci committed Sep 8, 2019
1 parent c0e6b62 commit b97eaae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/api/set/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addDataEvent } from '../listeners/emit'
import {
addOwnLeaf,
addOverrideLeafForKeys,
cleanBranchKeys
fireBranchKeys
} from './utils'
import { setOwnNew } from './own-new'
import { setOwnExisting } from './own-existing'
Expand Down Expand Up @@ -40,7 +40,7 @@ const setKeys = (branch, leaf, id, val, stamp, set) => {
keys.forEach(key => { leaf.keys.add(key) })
leaf.stamp = stamp
if (branch.branches.length) {
cleanBranchKeys(branch.branches, id, keys, stamp)
fireBranchKeys(branch.branches, id, keys, stamp)
}
addDataEvent(undefined, id, 'add-key')
}
Expand Down
7 changes: 6 additions & 1 deletion src/api/set/own-existing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const setOwnExistingReference = (branch, leaf, id, rT, stamp) => {
leaf.rT = true
leaf.val = rT
leaf.stamp = stamp

addReferenceFrom(branch, id, rT)
addDataEvent(undefined, id, 'set', leaf.depth)
return true
Expand Down Expand Up @@ -67,4 +68,8 @@ const setOwnExisting = (branch, leaf, id, val, stamp) => {
}
}

export { setOwnExistingVal, setOwnExistingReference, setOwnExisting }
export {
setOwnExistingVal,
setOwnExistingReference,
setOwnExisting
}
4 changes: 2 additions & 2 deletions src/api/set/own-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
addReferenceFrom,
checkReferenceByLeaf,
fixBranchReferences,
cleanBranchKeys
fireBranchKeys
} from './utils'

const setOwnNewVal = (_, leaf, id, val, stamp) => {
Expand Down Expand Up @@ -49,7 +49,7 @@ const setOwnNewKeys = (branch, leaf, id, val, stamp) => {
if (keys.size) {
leaf.stamp = stamp
if (branch.branches.length) {
cleanBranchKeys(branch.branches, id, keys, stamp)
fireBranchKeys(branch.branches, id, keys, stamp)
}
addDataEvent(undefined, id, 'add-key')
}
Expand Down
29 changes: 13 additions & 16 deletions src/api/set/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ const fixBranchReferences = (branches, rF, rT, rTold) =>
const leaf = branch.leaves[rF]
if (leaf === null) {
return
} else if (!Object.prototype.hasOwnProperty.call(branch.leaves, rF)) {
if (rTold) {
removeReferenceFrom(branch, rF, rTold)
}
addReferenceFrom(branch, rF, rT)
} else if (leaf.rT && Object.prototype.hasOwnProperty.call(leaf, 'val')) {
} else if (
Object.prototype.hasOwnProperty.call(branch.leaves, rF) &&
Object.prototype.hasOwnProperty.call(leaf, 'val') &&
leaf.rT
) {
if (leaf.val === rT) {
addAfterEmitEvent(() => {
delete leaf.val
Expand Down Expand Up @@ -134,12 +133,11 @@ const checkReferenceByLeaf = (branch, rTBranch, rT, cb) => {
}
}

const cleanBranchKeys = (branches, id, keys, stamp) =>
const fireBranchKeys = (branches, id, keys, stamp) =>
branches.forEach(branch => {
const keysNext = new Set(keys)
if (branch.leaves[id] === null) {
return
} else {
if (branch.leaves[id] !== null) {
const keysNext = new Set(keys)

keysNext.forEach(key => {
if (
Object.prototype.hasOwnProperty.call(branch.leaves, key) &&
Expand All @@ -151,12 +149,11 @@ const cleanBranchKeys = (branches, id, keys, stamp) =>

if (keysNext.size) {
addDataEvent(branch, id, 'add-key')
if (branch.branches.length) {
fireBranchKeys(branch.branches, id, keysNext, stamp)
}
}
}

if (branch.branches.length && keysNext.size) {
cleanBranchKeys(branch.branches, id, keysNext, stamp)
}
})

export {
Expand All @@ -167,5 +164,5 @@ export {
removeReferenceFrom,
checkReferenceByLeaf,
fixBranchReferences,
cleanBranchKeys
fireBranchKeys
}

0 comments on commit b97eaae

Please sign in to comment.