Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stimulus-events

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stimulus-events

Stimulus Event System

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Stimulus Events

Stimulus events is a simple Typescript library that uses the power of decorators to easily create an easy eventing system for communication between your different Stimulus controllers.

Never forget to call and manage removeEventListener on disconnect() again!

First, let's define an Events.ts file for our event constants! Helps us keep track of what's out there.

export const UserCountChanged = "UserCountChanged"

This isn't strictly necessary, but it helps keep your code more maintainable and is highly recommended.

import {UserCountChanged} from './Events';

class MyController extends Controller {
    
    @subscribeTo(UserCountChanged)
    updateUserCount(payload: Payload) {
        let {count} = payload
        // And yer off!
        // We'll automatically subscribe on connect() and unsubscribe on disconnect()
    }
}

And, triggering this from anywhere in your application is as easy as...

MainBus.send(UserCountChanged, {count: 3})

BOOM! That's it. All done. Time for a tea break.

FAQs

Package last updated on 21 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc