Giter Club home page Giter Club logo

nexus-event-bus's Introduction

Repository archived. All code was moved to https://github.com/keneanung/nexus-scripts and lives on there. For more background, please read https://keneanung.github.io/nexus-scripts/blog/2023/06/23/_a_new_home.

Iron Realms Nexus Event Bus

An implementation of the publish-subscriber pattern at its core.

Installation

To install the package, first download it to your machine via this link.

You can then proceed to install it as a normal package into your Nexus profile. You may have to log in and out after installing the package.

Basic Usage

When the package is installed, you can use it in any script reflex. First you will need to subscribe to an event.

eventBus.subscribe('myEvent', (data) => {
  console.log(data);
});

To raise an event, you can use the raise method.

eventBus.raise('myEvent', 'Hello World!');

This will print Hello World! to the console.

For documentation on the inidividual methods, advanced usage and some best practices, see the Nexus Event Bus documentation.

nexus-event-bus's People

Contributors

dependabot[bot] avatar keneanung avatar

Watchers

 avatar  avatar  avatar

nexus-event-bus's Issues

Better default onGMCP function

Recommend revising the packaged onGMCP function to a more functional starter version like:

eventBus.raise(args.gmcp_method, args.gmcp_args);

This allows subscribing to GMCP events rather than GMCP as an event.
eventBus.subscribe('Char.Vitals', (args)=>{nexusclient.display_notice(This is my hp: ${args.hp})})

Feature request to unsubscribe functions based on their string name

I do not know Typescript but something along the lines of:

public unsubscribe<T>(eventName: string, callback: EventCallback<T>) {
    let subscriptions: EventCallback<T>[];
    if (typeof callback === 'string') {
        let listener = this.subscriptions[eventName].find(e => e.name == callback);
        this.unbsubscribeFromEvent(subscriptions, listener);
        return;
    }
    if (eventName === '*') {
      subscriptions = this.subscriptionsToAll;
    } else {
      if (this.subscriptions[eventName] === undefined) {
        return;
      }
      subscriptions = this.subscriptions[eventName];
    }
    this.unsubscribeFromEvent(subscriptions, callback);
  }

Subscribed listeners poll

If the intent is for the subscriptions field to remain private add a getter that returns the subscription array as an array.

Functionality to troubleshoot event systems (in my experience) requires the ability to investigate if there is a rogue listener firing on an event.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.