mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 06:53:25 +02:00
Hook debug-mutations into lifecycle events (#2841)
This commit is contained in:
@@ -60,10 +60,25 @@ function DebugMutationsPlugin({ editor }) {
|
|||||||
debug(`${array.length} Mutations`, ...array)
|
debug(`${array.length} Mutations`, ...array)
|
||||||
})
|
})
|
||||||
|
|
||||||
// `findDOMNode` does not exist until later so we use `setTimeout`
|
/**
|
||||||
setTimeout(() => {
|
* The previously observed DOM node
|
||||||
|
*
|
||||||
|
* @type {DOMNode}
|
||||||
|
*/
|
||||||
|
|
||||||
|
let prevRootEl = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start observing the DOM node for mutations if it isn't being observed
|
||||||
|
*/
|
||||||
|
|
||||||
|
function start() {
|
||||||
const rootEl = editor.findDOMNode([])
|
const rootEl = editor.findDOMNode([])
|
||||||
|
|
||||||
|
if (rootEl === prevRootEl) return
|
||||||
|
|
||||||
|
debug('start')
|
||||||
|
|
||||||
observer.observe(rootEl, {
|
observer.observe(rootEl, {
|
||||||
childList: true,
|
childList: true,
|
||||||
characterData: true,
|
characterData: true,
|
||||||
@@ -71,7 +86,26 @@ function DebugMutationsPlugin({ editor }) {
|
|||||||
subtree: true,
|
subtree: true,
|
||||||
characterDataOldValue: true,
|
characterDataOldValue: true,
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
prevRootEl = rootEl
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop observing the DOM node for mutations
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
debug('stop')
|
||||||
|
|
||||||
|
observer.disconnect()
|
||||||
|
prevRootEl = null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
onComponentDidMount: start,
|
||||||
|
onComponentDidUpdate: start,
|
||||||
|
onComponentWillUnmount: stop,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DebugMutationsPlugin
|
export default DebugMutationsPlugin
|
||||||
|
Reference in New Issue
Block a user