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

@wdis/event

v1.0.13

Published

@wdis/event

Downloads

4

Readme

wdis-event npm version NPM Downloads

Install

npm install @wdis/event

Or

yarn install @wdis/event

Example of Global Events

// const { wdisEvent } = require('@wdis/event');
import { wdisEvent } from "@wdis/event";

const custonCallBack = (obj: any) => {
    console.log('on event');
    if (obj && obj.customKey_1) {
        console.log(obj.customKey_1);
    }
    if (obj && obj.customKey_2) {
        console.log(obj.customKey_2);
    }
};

wdisEvent.on('customEventGlobal', custonCallBack);
wdisEvent.on('custom:event:global2', custonCallBack);

wdisEvent.trigger('customEventGlobal', null);
setTimeout(() => {
    wdisEvent.trigger('custom:event:global2', {customKey_1: 'Test here using customKey_1'});
    setTimeout(() => {
        wdisEvent.emit('custom:event:global2', {customKey_2: 'Test here using customKey_2'});
    }, 1000);
}, 2000);

setTimeout(async () => {
    // Waiting for the end of the promise
    await wdisEvent.intercept('customEventGlobal', {customKey_1: 'Test here using customKey_1'});
}, 4000);

console.log('Global EventNames '+JSON.stringify(wdisEvent.exportNames()));

Example of Private Object Events and One Global

// const {WdisEvent, wdisEvent} = require('@wdis/event');
import { WdisEvent, wdisEvent } from "@wdis/event";

let _selfObj:ObjPrivate|null = null;
class ObjPrivate extends WdisEvent {
    public static CUSTOM_EVENT_GLOBAL       = 'global:from:objprivate:change';
    
    public static CUSTOM_EVENT_PRAIVATE     = 'customEventPrivate';
    public static CUSTOM_EVENT_PRAIVATE2    = 'custom:event:private2';
    public static CHANGE                    = 'change';
    private wdisEventGlobal: WdisEvent;
    constructor(){
        super();
        _selfObj = this;
        this.initCustomEvents();
        this.wdisEventGlobal = wdisEvent;
    }
    initCustomEvents() {
        this.on(ObjPrivate.CUSTOM_EVENT_PRAIVATE,       this.onCustomEventPrivate);
        this.on(ObjPrivate.CUSTOM_EVENT_PRAIVATE2,      this.onCustomEventPrivate2);
        this.on(ObjPrivate.CHANGE,                      this.onChange);
    }
    onChange(objChanged: {name:string}) {
        console.log(objChanged.name);
        // to external listening
        _selfObj?.wdisEventGlobal.emit(ObjPrivate.CUSTOM_EVENT_GLOBAL, objChanged);
    }
    onCustomEventPrivate() {
        console.log('onCustomEventPrivate2');
        _selfObj?.emit(ObjPrivate.CHANGE, {name: 'emited from private'});
    }
    onCustomEventPrivate2(customParam1: any, customParam2: any, customParam3: any) {
        console.log('onCustomEventPrivate with 3 custom params');
        console.log(customParam1);
        console.log(customParam2);
        console.log(customParam3);
        _selfObj?.emit(ObjPrivate.CHANGE, {name: 'emited from private2'});
    }
}

const wdisEventPrivateObj = new ObjPrivate();

const custonCallBackExternal = (obj: any) => {
    console.log('on custonCallBackExternal');
    if (obj && obj.customKey_1) {
        console.log(obj.customKey_1);
    }
    if (obj && obj.customKey_2) {
        console.log(obj.customKey_2);
    }
    return "Return from custonCallBackExternal to be used in interceptor";
};

// set new event listening 
wdisEvent.on(ObjPrivate.CUSTOM_EVENT_GLOBAL,                custonCallBackExternal);
wdisEventPrivateObj.on(ObjPrivate.CUSTOM_EVENT_PRAIVATE2,   custonCallBackExternal);
wdisEventPrivateObj.on('new:custom:event:private',          custonCallBackExternal);

// sending events with emit or trigger is the same thing
wdisEventPrivateObj.emit(ObjPrivate.CUSTOM_EVENT_PRAIVATE2, {customKey_1: 'Test here using customKey_1'}, {name:'teste to param 2'}, 'string to param 3');
setTimeout(() => {
    wdisEventPrivateObj.trigger(ObjPrivate.CUSTOM_EVENT_PRAIVATE, {customKey_1: 'Test here using customKey_1'});
    setTimeout(() => {
        wdisEventPrivateObj.emit(ObjPrivate.CUSTOM_EVENT_PRAIVATE, {customKey_2: 'Test here using customKey_2', customKey_1: 'Test here using customKey_1'});
    }, 1000);
}, 2000);

// sending events with interception can use them together with await, from the asynchronous function, to wait for success or error in an execution.
setTimeout(async () => {
    // Waiting for the end of the promise
    let result1 = await wdisEventPrivateObj.intercept('new:custom:event:private', {customKey_1: 'Test here using customKey_1 in event new:custom:event:private'});
    let result2 = await wdisEventPrivateObj.intercept(ObjPrivate.CUSTOM_EVENT_PRAIVATE2, {customKey_1: 'Test here using customKey_1'});
    console.log('result1: '+JSON.stringify(result1));
    console.log('result2: '+JSON.stringify(result2));
}, 4000);

console.log('EventNames '+JSON.stringify(wdisEventPrivateObj.exportNames()));
console.log('Global EventNames '+JSON.stringify(wdisEvent.exportNames()));