npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pea-event

v1.0.1

Published

a can be extended event model class

Downloads

3

Readme

pea-event · travis-ci Status soverage Status npm version MIT

An event model, extended in your js app

What is this?

pea-event is a class of js that helps you manage event/listener model

class App extends PeAEvent{};

var app =new App();
app.on('click',function(date){
  console.log('app be clicked',date);
});

app.execEventAll('click',[new Date]);

Is nothing to be surprised at?

How about this:

class App extends PeAEvent{};

var app =new App();
setTimeout(function(){
  app.execEventAll('load');
},1000);

(async function(){
  await app.wait('load');
  console.log('app loaded');
}());

It's very semantic right?

pea-event can do more than this, maybe you should look at the APIs

APIs

PeAEvent

Kind: global class

new PeAEvent([asTools])

recommend extend this class, direct construct will throw an error

| Param | Type | Default | Description | | --- | --- | --- | --- | | [asTools] | boolean | false | if you really want just construct it, call with true |

PeAEvent.on(eventType, listener, [options])

listen a event, add a listener for event

Kind: instance method of PeAEvent

| Param | Type | Description | | --- | --- | --- | | eventType | string | "*" means all | | listener | function | | | [options] | Object | | | options.once | boolean | If true, the listener would be automatically removed when invoked. |

PeAEvent.one(eventType, listener, [options])

listen a event but once. it's alias for PeAEvent#on(eventType,listener,{once:true})

Kind: instance method of PeAEvent

| Param | Type | Description | | --- | --- | --- | | eventType | string | "*" means all | | listener | function | | | [options] | Object | |

PeAEvent.off(eventType, listener) ⇒ boolean

remove a event listener.

note: if you use * in listener, waiter will be remove too

Kind: instance method of PeAEvent
Returns: boolean - success or no

| Param | Type | Description | | --- | --- | --- | | eventType | string | | | listener | function | string | "*" means all |

PeAEvent.wait(eventType, [checker]) ⇒ Promise

wait a event. you can add a checker, return a boolean to specify whether to wait if return a true, promise will be resolve

Kind: instance method of PeAEvent

| Param | Type | Description | | --- | --- | --- | | eventType | string | "*" means all | | [checker] | function | a checker function, it will call by event dispatch and received dispatch's argument, return a boolean for resolve or keep waiting |

PeAEvent.has(eventType) ⇒ Number

return the number of listeners for a given event type

Kind: instance method of PeAEvent

| Param | Type | | --- | --- | | eventType | string |

PeAEvent.reset()

reset all event listener

Kind: instance method of PeAEvent

PeAEvent.execEventAll(type, args) ⇒ Promise

trigger a event, exec this event's listener all. you can overwrite this method to changed you want, but overwrite method should use PeAEvent#execListener(listener ,arguments ,eventType) to exec a listener.

Kind: instance abstract method of PeAEvent

| Param | Type | Description | | --- | --- | --- | | type | string | event name to trigger | | args | Array | passed argument |

PeAEvent.execListener(listener, args, eventType)

how call a event listener. you can overwrite this method to changed you want.

Kind: instance abstract method of PeAEvent

| Param | Type | Description | | --- | --- | --- | | listener | function | event listener | | args | Array | the parameters passed in when the event is trigger | | eventType | string | the event name |

License

MIT