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

@xso/trigger

v0.1.1

Published

Trigger global events of the XSO framework.

Downloads

4

Readme

@xso/trigger

It fires global events that are intercepted in far away in the code.

Compatible with pure JavaScript, XSO components, React, Vue, Angular, Svelte, and more.

Remember that, the trigger works spread inside functions and the source code files. With the key, you can interact anywhere.

A simple way to replace the complexity of Redux and others.

Documentation

Here is the official website with the full documentation:

Install

To start playing with XSO COM:

npm install -S @xso/trigger

But better, is to use the PNPM:

pnpm install @xso/trigger

Or if you prefer Yarn:

yarn add -S @xso/trigger

Or even another package manager.

How To Use

Example of the capabilities supported in the XSO trigger events:

import trigger from "@xso/trigger";

const MESSAGE_KEY = "MESSAGE";

const mainFunc = (message)=> {
    console.warn('Main:', message);
};

// Set a function to key:
trigger.set(MESSAGE_KEY, mainFunc);

// Append more functions to the key:
trigger.add(MESSAGE_KEY, (message)=> {
    console.log('Client 1:', message);
});

// Append more functions to the key:
trigger.add(MESSAGE_KEY, (message)=> {
    console.log('Client 2:', message);
});

// Execute the key with args:
trigger(MESSAGE_KEY, 'Hello!');

function showKeyDetails() {
    // Gets the latest args passed to the key:
    trigger.get(MESSAGE_KEY, (message) => {
        console.error('The last message sent:', message);
    });
    // Get all functions attached to the key:
    console.log('Event functions:', trigger.events(MESSAGE_KEY));
    // Get latest args stored:
    console.log('Latest args stored:', trigger.stored(MESSAGE_KEY));
}
showKeyDetails();

console.log('1...');

window.setTimeout(()=> {
    trigger(MESSAGE_KEY, 'Hi there!');
    showKeyDetails();
    console.log('2...');
}, 1000);

window.setTimeout(()=> {
    // Remove function from the key:
    trigger.del(MESSAGE_KEY, mainFunc);
    // Execute the key with other arg:
    trigger(MESSAGE_KEY, 'Main was kicked!');
    showKeyDetails();
    console.log('3...');
}, 2000);

window.setTimeout(()=> {
    // Reset the key with only a function:
    trigger.set(MESSAGE_KEY, mainFunc);
    // Execute the key with other arg:
    trigger(MESSAGE_KEY, 'Main is back and no clients anymore!');
    showKeyDetails();
    console.log('4...');
}, 3000);

window.setTimeout(()=> {
    // Removes all functions attached to the key:
    trigger.clear(MESSAGE_KEY);
    trigger(MESSAGE_KEY, 'No one there!?');
    showKeyDetails();
    console.log('5...');
}, 4000);

window.setTimeout(()=> {
    // Remove the key and everything else:
    trigger.purge(MESSAGE_KEY);
    // Check if the key exists:
    if (trigger.exists(MESSAGE_KEY)) {
        console.warn('Key exists yet...');
    } else {
        console.error('Key removed...');
    }
}, 5000);

Vanilla JS in HTML

Here is an integration directly in the raw HTML with pure JavaScript, like this:

<!--
Here is the bundle JS file to download:
https://github.com/xsojs/trigger/blob/main/dist/xso-trigger.umd.js
-->
<script src="xso-trigger.umd.js"></script>

<script>
const ACTION_KEY = 'My-Action';
// Append a function to the key:
trigger.add(ACTION_KEY, (payload)=> {
    console.log(
        `${ACTION_KEY} trigger payload:`,
        payload
    );
});

trigger.add(ACTION_KEY, (payload)=> {
    alert('Trigger worked! See the payload in console log.');
});

// Execute the key with args:
trigger(ACTION_KEY, { type: 'message', content: 'Hello world.'});
</script>