{"id":26912954,"url":"https://github.com/tfreeborough/venti","last_synced_at":"2025-04-01T15:38:33.362Z","repository":{"id":59967396,"uuid":"50431470","full_name":"tfreeborough/Venti","owner":"tfreeborough","description":"Ultra-tiny custom event emitter for Typescript with ZERO dependencies","archived":false,"fork":false,"pushed_at":"2022-10-10T12:27:10.000Z","size":28,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-12T12:17:43.377Z","etag":null,"topics":["events","hacktoberfest","javascript","javascript-library","typescript-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/tfreeborough.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":"2016-01-26T13:49:06.000Z","updated_at":"2023-09-22T13:51:36.000Z","dependencies_parsed_at":"2023-01-19T19:33:35.026Z","dependency_job_id":null,"html_url":"https://github.com/tfreeborough/Venti","commit_stats":null,"previous_names":["tfreeborough/venti","angrytoad/venti"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfreeborough%2FVenti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfreeborough%2FVenti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfreeborough%2FVenti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfreeborough%2FVenti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tfreeborough","download_url":"https://codeload.github.com/tfreeborough/Venti/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246664175,"owners_count":20814038,"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":["events","hacktoberfest","javascript","javascript-library","typescript-library"],"created_at":"2025-04-01T15:38:32.759Z","updated_at":"2025-04-01T15:38:33.352Z","avatar_url":"https://github.com/tfreeborough.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Venti ![Venti Logo](http://i.imgur.com/8NWTW1r.png \"Venti\")\nUltra-tiny custom event emitter for Javascript \n\n### NPM - https://www.npmjs.com/package/venti-js\n\nA very simple out of the box library I first made in 2016 that allows you to bind multiple callback to an event and call it with/without data. Perfect if you just want a quick and easy way to call events in an application without worrying about prop drilling.\n\n###Installation\nTo install from npm, run the following:\n```\nnpm install --save venti-js\n```\n\n### Usage\n\n---\n\n#### Register Events\nRegister an event name with the callback you want to call:\n\n```typescript\nventi.on('eventName',functionName);\n```\n\n---\n\n#### Unregistering Events\n\nUnregistering events is very simple just pass the event name to unbind all callbacks\n\n```typescript\nventi.off('eventName');\n```\n\n\nOr you can pass the callback as the second parameter in order to unregister that specific function from the event.\n\n```typescript\nventi.off('eventName',callback);\n```\n\n---\n\n#### Trigger Events\nTriggering events is simple and done as follows:\n\n```typescript\nventi.trigger('eventName');\n```\n\nYou can also pass data into your trigger that will be passed to the callback:\n\n```typescript\nventi.trigger('eventName',{Data Goes Here});\n```\n\n---\n\n#### How to use data\nYour data passed as the second argument in `.trigger`is sent as one argument\ninto the callback as an object.\n\n```typescript\nventi.on('myFunctionEvent',myFunction);\nventi.trigger('myFunctionEvent',{names:['Tony','Gus','Fred']});\n```\n\nYour callback would look like this...\n\n```typescript\nmyFunction(data){\n  console.log(data.names); //Prints ['Tony','Gus','Fred']\n}\n```\n\n---\n\n#### Debugging\n\nVenti logs all events that are triggered, to view the log simply use.\n\n```typescript\nventi.eventLog(50) //Optional limit parameter (E.G. Only show the most recent 50)\n```\n\nBy default if no parameter is passed to `.eventLog()` then Venti defaults to 1000; you can change this by modifying `venti.eventLogLimit`.\n\n### Does this work with React?\nYes, just import it like you would any modern ES6 package:\n```typescript\nimport venti from 'venti-js'\n```\n\nTypical react usage in a useEffect\n\n```typescript\nimport React, { ReactElement, useEffect, useState } from 'react';\nimport venti from 'venti-js';\n\nexport const MyComponent: React.FC = (): ReactElement =\u003e {\n  const [modalOpen, setModalOpen] = useState(false);\n  const [modalTitle, setModalTitle] = useState('');\n\n  const handleOpenModal = () =\u003e {\n    setModalOpen(true);\n  };\n\n  const handleSetModalTitle = (data) =\u003e {\n    setModalTitle(data.title);\n  };\n\n  useEffect(() =\u003e {\n    venti.on('modalOpen', handleOpenModal);\n    venti.on('setModalTitle', handleSetModalTitle);\n\n    return () =\u003e {\n      venti.off('modalOpen');\n      venti.off('setModalTitle');\n    };\n  }, []);\n\n  if (!modalOpen) {\n    return null;\n  }\n  \n  return (\n    \u003cdiv className=\"myModal\"\u003e\n      \u003ch1\u003e{ modalTitle }\u003c/h1\u003e\n    \u003c/div\u003e\n  );\n};\n\nexport default MyComponent;\n```\n\nUsage with multiple callbacks\n\n```typescript\nimport React, { ReactElement, useEffect, useState } from 'react';\nimport venti from 'venti-js';\n\nexport const MyComponent: React.FC = (): ReactElement =\u003e {\n  const [modalOpen, setModalOpen] = useState(false);\n  const [formState, setFormState] = useState({});\n\n  const handleOpenModal = () =\u003e {\n    setModalOpen(true);\n  };\n  \n  const handleResetFormState = () =\u003e {\n    setFormState({});  \n  }\n\n  useEffect(() =\u003e {\n    venti.on('modalOpen', handleOpenModal);\n    venti.on('modalOpen', handleResetFormState);\n\n    return () =\u003e {\n      venti.off('modalOpen');\n    };\n  }, []);\n\n  if (!modalOpen) {\n    return null;\n  }\n  \n  return (\n    \u003cdiv className=\"myModal\"\u003e\n      // Form Stuff goes here\n    \u003c/div\u003e\n  );\n};\n\nexport default MyComponent;\n```\n\n\n### Misc\n\nAs it is required by the logging system, Venti can also return the plaintext name of a callback, simply use `venti.nameFromFunction(callback)` to retrieve the name of the function, this might be useful if you wish to log custom messages of your own.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfreeborough%2Fventi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftfreeborough%2Fventi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfreeborough%2Fventi/lists"}