Change to `expand` and `collapse` methods which accept a callback
This commit is contained in:
parent
637aa62762
commit
2a885ac5ef
|
@ -47,6 +47,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button id="expandAll">expand all</button>
|
<button id="expandAll">expand all</button>
|
||||||
|
<button id="expand2">expand 2 levels</button>
|
||||||
<button id="collapseAll">collapse all</button>
|
<button id="collapseAll">collapse all</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -159,11 +160,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('expandAll').onclick = function expandAll () {
|
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 () {
|
document.getElementById('collapseAll').onclick = function collapseAll () {
|
||||||
testEditor.collapseAll()
|
testEditor.collapse(() => false)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -39,13 +39,9 @@
|
||||||
|
|
||||||
export let onChangeJson = () => {}
|
export let onChangeJson = () => {}
|
||||||
|
|
||||||
function expand (path) {
|
|
||||||
return path.length < 1
|
|
||||||
}
|
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
console.time('syncState')
|
console.time('syncState')
|
||||||
state = syncState(doc, state, [], expand)
|
state = syncState(doc, state, [], (path) => path.length < 1)
|
||||||
console.timeEnd('syncState')
|
console.timeEnd('syncState')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,12 +55,12 @@
|
||||||
})
|
})
|
||||||
let historyState = history.getState()
|
let historyState = history.getState()
|
||||||
|
|
||||||
export function expandAll () {
|
export function expand (callback = () => true) {
|
||||||
state = syncState(doc, state, [], () => true, true)
|
state = syncState(doc, state, [], callback, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function collapseAll () {
|
export function collapse (doCollapse = () => false) {
|
||||||
state = syncState(doc, state, [], () => false, true)
|
state = syncState(doc, state, [], callback, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get() {
|
export function get() {
|
||||||
|
|
Loading…
Reference in New Issue