Add support iterator
sirenkovladd opened this issue · comments
Vlad Sirenko commented
example
const { on } = require('events');
const { request } = require('https');
const html = require('htm');
function h(type, props, ...children) {
return { type, props, children };
}
request('https://nodejs.org/en', async (res) => {
const iterator = on(res, "data");
const domIterator = html.bind(h).iterator(iterator);
for await (const element of emitter) {
console.log(element);
}
}).end();
request('https://nodejs.org/en', async (res) => {
const iterator = on(res, "data");
const domEmitter = html.bind(h).emitter(iterator);
domEmitter.on('div', (element) => {
console.log('emitter', element);
});
domEmitter.on('end', () => {
console.log('end');
});
}).end();
Vlad Sirenko commented
Motivation
sometimes the page is too big, but you need to get the elements that are at the beginning
an iterator or emitter would allow you to get the information you need without going through the entire page