Change to `expand` and `collapse` methods which accept a callback

This commit is contained in:
josdejong 2020-06-02 21:58:40 +02:00
parent 637aa62762
commit 2a885ac5ef
2 changed files with 12 additions and 11 deletions

View File

@ -47,6 +47,7 @@
</p>
<p>
<button id="expandAll">expand all</button>
<button id="expand2">expand 2 levels</button>
<button id="collapseAll">collapse all</button>
</p>
@ -159,11 +160,15 @@
}
document.getElementById('expandAll').onclick = function expandAll () {
testEditor.expandAll()
testEditor.expand(() => true)
}
document.getElementById('expand2').onclick = function expandAll () {
testEditor.expand(path => path.length < 2)
}
document.getElementById('collapseAll').onclick = function collapseAll () {
testEditor.collapseAll()
testEditor.collapse(() => false)
}
</script>
</body>

View File

@ -39,13 +39,9 @@
export let onChangeJson = () => {}
function expand (path) {
return path.length < 1
}
$: {
console.time('syncState')
state = syncState(doc, state, [], expand)
state = syncState(doc, state, [], (path) => path.length < 1)
console.timeEnd('syncState')
}
@ -59,12 +55,12 @@
})
let historyState = history.getState()
export function expandAll () {
state = syncState(doc, state, [], () => true, true)
export function expand (callback = () => true) {
state = syncState(doc, state, [], callback, true)
}
export function collapseAll () {
state = syncState(doc, state, [], () => false, true)
export function collapse (doCollapse = () => false) {
state = syncState(doc, state, [], callback, true)
}
export function get() {