/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/rich-text/src/create-element.js
25 строк
993 B
Andrew Duthie
RichText: Reuse DOM document across calls to createEmpty (#12402)
30 ноя 2018, 19:29
Не верифицирован
30 ноя 2018, 19:29
4178f2d
Код
Авторство
О чём код?
/** * Parse the given HTML into a body element. * * Note: The current implementation will return a shared reference, reset on * each call to `createElement`. Therefore, you should not hold a reference to * the value to operate upon asynchronously, as it may have unexpected results. * * @param {HTMLDocument} document The HTML document to use to parse. * @param {string} html The HTML to parse. * * @return {HTMLBodyElement} Body element with parsed HTML. */ export function createElement( { implementation }, html ) { // Because `createHTMLDocument` is an expensive operation, and with this // function being internal to `rich-text` (full control in avoiding a risk // of asynchronous operations on the shared reference), a single document // is reused and reset for each call to the function. if ( ! createElement.body ) { createElement.body = implementation.createHTMLDocument( '' ).body; } createElement.body.innerHTML = html; return createElement.body; }