Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support iterator #255

Open
sirenkovladd opened this issue Jan 31, 2024 · 1 comment
Open

Add support iterator #255

sirenkovladd opened this issue Jan 31, 2024 · 1 comment

Comments

@sirenkovladd
Copy link

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();
@sirenkovladd
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant