Installations
npm install strongly-typed-events
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
>=4.2.4
Node Version
18.17.0
NPM Version
lerna/7.1.4/node@v18.17.0+x64 (win32)
Score
79.7
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (89.55%)
HTML (5.6%)
JavaScript (4.23%)
PowerShell (0.62%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
1,147,535
Last Day
780
Last Week
4,244
Last Month
21,387
Last Year
188,095
GitHub Statistics
MIT License
138 Stars
747 Commits
14 Forks
8 Watchers
6 Branches
9 Contributors
Updated on Dec 19, 2024
Bundle Size
21.24 kB
Minified
2.69 kB
Minified + Gzipped
Package Meta Information
Latest Version
3.0.11
Package Id
strongly-typed-events@3.0.11
Unpacked Size
16.74 kB
Size
4.31 kB
File Count
5
NPM Version
lerna/7.1.4/node@v18.17.0+x64 (win32)
Node Version
18.17.0
Published on
Aug 09, 2023
Total Downloads
Cumulative downloads
Total Downloads
1,147,535
Last Day
26%
780
Compared to previous day
Last Week
-13.6%
4,244
Compared to previous week
Last Month
42.4%
21,387
Compared to previous month
Last Year
-25%
188,095
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Strongly Typed Events
Add the power of events to your projects. We even have 3 flavors for you.
Event types
This project gives you the following event types:
- Events - styled after the way .Net implements events. With each event you'll get a
sender
and anargument
object. If you use typescript, you can implement them using generics. - Simple events - basically the same thing, with only 1 argument.
- Signals - for when no data is needed, just the firing of the event is enough.
Subscription made easy
An example says more than a 1000 words. Imagine if you have events like this on your class:
1let clock = new Clock("Smu", 1000); 2 3//log the ticks to the console - this is a signal event 4clock.onTick.subscribe(() => console.log("Tick!")); 5 6//log the sequence parameter to the console - this is a simple event 7clock.onSequenceTick.subscribe(s => console.log(`Sequence: ${s}`)); 8 9//log the name of the clock and the tick argument to the console - this is an event 10clock.onClockTick.subscribe((c, n) => 11 console.log(`${c.name} ticked ${n} times.`) 12);
Events made easy
So let's look at the implementation from a TypeScript perspective. (Do you program NodeJs without typescript? Check this)
1import { SignalDispatcher, SimpleEventDispatcher, EventDispatcher } from "strongly-typed-events"; 2 3class Clock { 4 private _onTick = new SignalDispatcher(); 5 private _onSequenceTick = new SimpleEventDispatcher<number>(); 6 private _onClockTick = new EventDispatcher<Clock, number>(); 7 private _ticks: number = 0; 8 9 constructor(public name: string, timeout: number) { 10 setInterval(() => { 11 this._ticks += 1; 12 this._onTick.dispatch(); 13 this._onSequenceTick.dispatch(this._ticks); 14 this._onClockTick.dispatch(this, this._ticks); 15 }, timeout); 16 } 17 18 public get onTick() { 19 return this._onTick.asEvent(); 20 } 21 22 public get onSequenceTick() { 23 return this._onSequenceTick.asEvent(); 24 } 25 26 public get onClockTick() { 27 return this._onClockTick.asEvent(); 28 } 29}
Stopping events
You can stop events from being propagated.
1let dispatcher = new SignalDispatcher(); 2 3 let a = 0; 4 dispatcher.sub(ev => { 5 a++; 6 if (a > 2) { 7 ev.stopPropagation(); 8 } 9 }); 10 11 let b = 0; 12 dispatcher.sub(() => { b++; }); 13 14 dispatcher.dispatch(); 15 dispatcher.dispatch(); 16 dispatcher.dispatch(); 17 dispatcher.dispatch(); 18 19 // a should be 4, because 4 dispatches are done."); 20 // b should be 2, because events after the 2nd dispatch are stopped." 21
Packages
The project is separated into multiple packages, so you only need to include what you need. We have the following packages:
Package | Description |
---|---|
ste-core | Package that contains all the building blocks for the creation of events. The dispatcher implementation is its main hero. |
ste-events or ste-promise-events | Events that are modeled after .Net with a sender and argument . If you use typescript, you can leverage the support for generics and get strongly typed code. |
ste-simple-events or ste-promise-simple-events | A simpler version of the ste-event -event. No sender, just an argument. |
ste-signals or ste-promise-signals | A signal is even simpler, it is just a callback for when you need to be alerted without any scope. |
strongly-typed-events | This package includes everything. |
ste-browser | Helps to host events in the browser. |
Documentation
This project will help you to add events, event handling en event dispatching to your classes. To get you started, check:
- How to add an event to a class?
- How to add an event to an interface?
- How to add multiple events to a class?
- How to add dynamic named events to a class?
- How to do asynchronous event dispatching?
- On events, dispatchers and lists (a general explanation of the system)
- How to use Strongly Typed Events in Node.js?
- Some unsubscribe strategies
Check the documentation or the examples for more information.
History
The change history can be found here.
Maintenance
This project is maintained by Kees C. Bakker.

No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/merge.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/KeesCBakker/Strongly-Typed-Events-for-TypeScript/merge.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/KeesCBakker/Strongly-Typed-Events-for-TypeScript/node.js.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/KeesCBakker/Strongly-Typed-Events-for-TypeScript/node.js.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/merge.yml:1
- Warn: no topLevel permission defined: .github/workflows/node.js.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Reason
15 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx
- Warn: Project is vulnerable to: GHSA-8hc4-vh64-cxmj
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4vvj-4cpr-p986
Score
2.8
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreGathering detailed insights and metrics for strongly-typed-events