/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/core/dom/stream/detached.js
47 строк
1 KB
Ryan Cebulko
♻️ Migrate most of #core to pass TS typechecking (#37141)
09 дек 2021, 21:22
Не верифицирован
09 дек 2021, 21:22
58a1c29
Код
Авторство
О чём код?
import {devAssert} from '#core/assert'; export class DetachedDomStream { /** * @param {Window} win * @param {function(Document):void} onChunk * @param {function(Document):void} onEnd */ constructor(win, onChunk, onEnd) { /** @const @private {function(Document):void} */ this.onChunk_ = onChunk; /** @const @private {function(Document):void} */ this.onEnd_ = onEnd; /** @const @private {Document} */ this.detachedDoc_ = win.document.implementation.createHTMLDocument(''); this.detachedDoc_.open(); /** @private {boolean} */ this.eof_ = false; } /** * Write chunk into detached doc, and call given chunk cb. * @public * @param {string} chunk */ write(chunk) { devAssert(!this.eof_, 'Detached doc already closed.'); if (chunk) { this.detachedDoc_.write(chunk); } this.onChunk_(this.detachedDoc_); } /** * Called when stream is finished. Close the detached doc, and call cb. * @public */ close() { this.eof_ = true; this.detachedDoc_.close(); this.onEnd_(this.detachedDoc_); } }