Skip to content

Add support iterator #255

Open
Open

Description

@sirenkovladd

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();

Activity

  1. sirenkovladd commented on Jan 31, 2024

    @sirenkovladd
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions