{"id":16973832,"url":"https://github.com/pea3nut/pea-event","last_synced_at":"2025-08-19T00:11:48.745Z","repository":{"id":57321604,"uuid":"102464255","full_name":"pea3nut/pea-event","owner":"pea3nut","description":"An event model, extended in your js app","archived":false,"fork":false,"pushed_at":"2017-10-20T07:00:02.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T13:12:25.492Z","etag":null,"topics":["class","event","event-model","extend"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pea3nut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-05T09:48:06.000Z","updated_at":"2018-07-11T07:59:13.000Z","dependencies_parsed_at":"2022-08-25T21:00:58.605Z","dependency_job_id":null,"html_url":"https://github.com/pea3nut/pea-event","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pea3nut/pea-event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pea3nut%2Fpea-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pea3nut%2Fpea-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pea3nut%2Fpea-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pea3nut%2Fpea-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pea3nut","download_url":"https://codeload.github.com/pea3nut/pea-event/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pea3nut%2Fpea-event/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271078587,"owners_count":24695473,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["class","event","event-model","extend"],"created_at":"2024-10-14T01:03:46.391Z","updated_at":"2025-08-19T00:11:48.694Z","avatar_url":"https://github.com/pea3nut.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pea-event \u0026middot; [![travis-ci Status](https://travis-ci.org/pea3nut/pea-event.svg?branch=master)](https://www.travis-ci.org/pea3nut/pea-event) [![soverage Status](https://coveralls.io/repos/github/pea3nut/pea-event/badge.svg?branch=master)](https://coveralls.io/github/pea3nut/pea-event?branch=master) [![npm version](https://img.shields.io/npm/v/pea-event.svg?style=flat)](https://www.npmjs.com/package/pea-event) [![MIT](https://img.shields.io/dub/l/vibe-d.svg)](LICENSE)\n\nAn event model, extended in your js app\n\n# What is this?\n\npea-event is a class of js that helps you manage event/listener model\n\n```js\nclass App extends PeAEvent{};\n\nvar app =new App();\napp.on('click',function(date){\n  console.log('app be clicked',date);\n});\n\napp.execEventAll('click',[new Date]);\n```\n\nIs nothing to be surprised at? \n\nHow about this:\n\n```js\nclass App extends PeAEvent{};\n\nvar app =new App();\nsetTimeout(function(){\n  app.execEventAll('load');\n},1000);\n\n(async function(){\n  await app.wait('load');\n  console.log('app loaded');\n}());\n```\n\nIt's very semantic right?\n\npea-event can do more than this, maybe you should look at the [APIs](#apis)\n\n# APIs\n\n\u003c!--jsdoc will generate here--\u003e\n\n\u003c!--jsdoc--\u003e\n\n\u003ca name=\"PeAEvent\"\u003e\u003c/a\u003e\n\n## PeAEvent\n**Kind**: global class  \n\n* [PeAEvent](#PeAEvent)\n    * [new PeAEvent([asTools])](#new_PeAEvent_new)\n    * [.on(eventType, listener, [options])](#PeAEvent+on)\n    * [.one(eventType, listener, [options])](#PeAEvent+one)\n    * [.off(eventType, listener)](#PeAEvent+off) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\n    * [.wait(eventType, [checker])](#PeAEvent+wait) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\n    * [.has(eventType)](#PeAEvent+has) ⇒ \u003ccode\u003eNumber\u003c/code\u003e\n    * [.reset()](#PeAEvent+reset)\n    * *[.execEventAll(type, args)](#PeAEvent+execEventAll) ⇒ \u003ccode\u003ePromise\u003c/code\u003e*\n    * *[.execListener(listener, args, eventType)](#PeAEvent+execListener)*\n\n\u003ca name=\"new_PeAEvent_new\"\u003e\u003c/a\u003e\n\n### new PeAEvent([asTools])\nrecommend extend this class, direct construct will throw an error\n\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| [asTools] | \u003ccode\u003eboolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | if you really want just construct it, call with true |\n\n\u003ca name=\"PeAEvent+on\"\u003e\u003c/a\u003e\n\n### PeAEvent.on(eventType, listener, [options])\nlisten a event, add a listener for event\n\n**Kind**: instance method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| eventType | \u003ccode\u003estring\u003c/code\u003e | \"*\" means all |\n| listener | \u003ccode\u003efunction\u003c/code\u003e |  |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e |  |\n| options.once | \u003ccode\u003eboolean\u003c/code\u003e | If true, the listener would be automatically removed when invoked. |\n\n\u003ca name=\"PeAEvent+one\"\u003e\u003c/a\u003e\n\n### PeAEvent.one(eventType, listener, [options])\nlisten a event but once.\rit's alias for PeAEvent#on(eventType,listener,{once:true})\n\n**Kind**: instance method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| eventType | \u003ccode\u003estring\u003c/code\u003e | \"*\" means all |\n| listener | \u003ccode\u003efunction\u003c/code\u003e |  |\n| [options] | \u003ccode\u003eObject\u003c/code\u003e |  |\n\n\u003ca name=\"PeAEvent+off\"\u003e\u003c/a\u003e\n\n### PeAEvent.off(eventType, listener) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\nremove a event listener.\r\u003e note: if you use * in listener, waiter will be remove too\n\n**Kind**: instance method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n**Returns**: \u003ccode\u003eboolean\u003c/code\u003e - success or no  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| eventType | \u003ccode\u003estring\u003c/code\u003e |  |\n| listener | \u003ccode\u003efunction\u003c/code\u003e \\| \u003ccode\u003estring\u003c/code\u003e | \"*\" means all |\n\n\u003ca name=\"PeAEvent+wait\"\u003e\u003c/a\u003e\n\n### PeAEvent.wait(eventType, [checker]) ⇒ \u003ccode\u003ePromise\u003c/code\u003e\nwait a event.\ryou can add a checker, return a boolean to specify whether to wait\rif return a true, promise will be resolve\n\n**Kind**: instance method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| eventType | \u003ccode\u003estring\u003c/code\u003e | \"*\" means all |\n| [checker] | \u003ccode\u003efunction\u003c/code\u003e | a checker function, it will call by event dispatch and received dispatch's argument, return a boolean for resolve or keep waiting |\n\n\u003ca name=\"PeAEvent+has\"\u003e\u003c/a\u003e\n\n### PeAEvent.has(eventType) ⇒ \u003ccode\u003eNumber\u003c/code\u003e\nreturn the number of listeners for a given event type\n\n**Kind**: instance method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\n| Param | Type |\n| --- | --- |\n| eventType | \u003ccode\u003estring\u003c/code\u003e | \n\n\u003ca name=\"PeAEvent+reset\"\u003e\u003c/a\u003e\n\n### PeAEvent.reset()\nreset all event listener\n\n**Kind**: instance method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\u003ca name=\"PeAEvent+execEventAll\"\u003e\u003c/a\u003e\n\n### *PeAEvent.execEventAll(type, args) ⇒ \u003ccode\u003ePromise\u003c/code\u003e*\ntrigger a event, exec this event's listener all.\ryou can overwrite this method to changed you want,\rbut overwrite method should use PeAEvent#execListener(listener ,arguments ,eventType) to exec a listener.\n\n**Kind**: instance abstract method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| type | \u003ccode\u003estring\u003c/code\u003e | event name to trigger |\n| args | \u003ccode\u003eArray\u003c/code\u003e | passed argument |\n\n\u003ca name=\"PeAEvent+execListener\"\u003e\u003c/a\u003e\n\n### *PeAEvent.execListener(listener, args, eventType)*\nhow call a event listener.\ryou can overwrite this method to changed you want.\n\n**Kind**: instance abstract method of [\u003ccode\u003ePeAEvent\u003c/code\u003e](#PeAEvent)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| listener | \u003ccode\u003efunction\u003c/code\u003e | event listener |\n| args | \u003ccode\u003eArray\u003c/code\u003e | the parameters passed in when the event is trigger |\n| eventType | \u003ccode\u003estring\u003c/code\u003e | the event name |\n\n\n\n\u003c!--/jsdoc--\u003e\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpea3nut%2Fpea-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpea3nut%2Fpea-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpea3nut%2Fpea-event/lists"}