Socket
Socket
Sign inDemoInstall

stimulus-events

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stimulus-events

Stimulus Event System


Version published
Weekly downloads
2
Maintainers
1
Install size
215 kB
Created
Weekly downloads
 

Readme

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

Last updated on 21 Jan 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc