{"id":16398854,"url":"https://github.com/sauldoescode/eventilator","last_synced_at":"2025-04-04T14:25:54.557Z","repository":{"id":43001604,"uuid":"134046555","full_name":"SaulDoesCode/eventilator","owner":"SaulDoesCode","description":"cute event manager with super powers","archived":false,"fork":false,"pushed_at":"2022-12-03T17:25:21.000Z","size":458,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T00:18:53.110Z","etag":null,"topics":["addlistener","dom","dom-manipulation","event-handling","event-management","javascript-library","proxy","utility-library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SaulDoesCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-19T09:03:20.000Z","updated_at":"2024-05-15T08:14:48.000Z","dependencies_parsed_at":"2023-01-23T14:30:11.743Z","dependency_job_id":null,"html_url":"https://github.com/SaulDoesCode/eventilator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Feventilator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Feventilator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Feventilator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SaulDoesCode%2Feventilator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SaulDoesCode","download_url":"https://codeload.github.com/SaulDoesCode/eventilator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247192369,"owners_count":20899078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addlistener","dom","dom-manipulation","event-handling","event-management","javascript-library","proxy","utility-library"],"created_at":"2024-10-11T05:14:05.254Z","updated_at":"2025-04-04T14:25:54.531Z","avatar_url":"https://github.com/SaulDoesCode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eventilator: but can your event manager do this?\n\n## API:\n```js\n  eventilator(\n    once Boolean,\n    target EventTarget|String|Array,\n    type String|Object\u003cString, Function\u003e,\n    =handle Function,\n    =options Boolean|Object = false\n  )\n```\n* ``.on/once['any-event-name'] | .on/once(target, event, handle, options)`` - add listener\n* ``.on/once(target, { event: handle })`` - add listeners\n* ``.off(target, event, handle) | handle.off`` - remove listener\n* ``.emit(target, type, detail) | handle.emit(type, detail)`` - emit event\n* ``.curry`` - extra (used internally but why not share)\n\n```js\n  const {on, once} = eventilator\n\n  let count = 0\n  const handle = on.anyEvent('div.target', (event, target) =\u003e {\n    count++\n  })\n\n  console.log(handle.target instanceof Element)\n\n  handle.emit('anyEvent')\n  handle.off() // same as handle == handle.off\n  \n  console.log(`\n    The handler is currently ${handle.ison ? 'on' : 'off'}.\n  `)\n\n  handle.emit('anyEvent')\n  handle.on()\n\n  console.log(`\n    The handler is currently ${handle.ison ? 'on' : 'off'}.\n  `)\n\n  handle.emit('anyEvent')\n\n\n  setTimeout(() =\u003e {\n    console.log(`The count should be 2 it is ${count}`)\n  }, 5)\n```\n\n```js\n  const {on, once} = eventilator\n\n  const handles = once('div.fancy-element', {\n    click (event, fancyElement) {},\n    keydown (event, fancyElement) {}\n  })\n\n  const {\n    click: {off: clickOff},\n    keydown: {off: keydownOff}\n  } = handles\n\n  try {\n    await someUnavailableOperation()\n  } catch (e) {\n    handles.click.off()\n  }\n```\n\nArrays or Selectors finding multiple elements works as well.\n```js\nconst [aHndl, bHndl, cHndl] = on.pointerover([a, b, c], (e, elementX) =\u003e {\n  // do something\n})\n\naHndl.off()\nbHndl.off()\ncHndl.off()\n\n// or\nconst handlers = on.pointerover('main \u003e div.fancy-card', (e, cardDiv) =\u003e {\n  // do something\n})\nhandlers.off() // \u003c- loops over each and turns'em off\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsauldoescode%2Feventilator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsauldoescode%2Feventilator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsauldoescode%2Feventilator/lists"}