-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui-contract-editor): update formulas when dependent variables ch…
…ange (#171) * feat(ui-contract-editor): update formulas when dependent variables change Signed-off-by: Dan Selman <[email protected]>
- Loading branch information
Showing
5 changed files
with
97 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import ContractEditor from './ContractEditor'; | ||
import getChildren from './utilities/getChildren'; | ||
|
||
export { getChildren }; | ||
export default ContractEditor; |
28 changes: 28 additions & 0 deletions
28
packages/ui-contract-editor/src/lib/utilities/getChildren.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Recursively match nodes in a slate dom using a matching function | ||
* @param {*} node a slate node | ||
* @param {*} matcher a matching function | ||
* @returns {[*]} the array of matched nodes | ||
*/ | ||
const getChildren = (node, matcher) => { | ||
if (matcher(node)) { | ||
return node; | ||
} | ||
|
||
if (node.children) { | ||
let result = []; | ||
node.children.forEach(n => { | ||
const r = getChildren(n, matcher); | ||
if (Array.isArray(r)) { | ||
result = result.concat(r); | ||
} else { | ||
result.push(r); | ||
} | ||
}); | ||
return result; | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
export default getChildren; |