Skip to content

Commit

Permalink
Updating everything to the latest (#30)
Browse files Browse the repository at this point in the history
* deps + compile

* tests fixed

* fixed docs

* docs

* docs finished

* adding ci

* ci

* ci

* ci

* ci
  • Loading branch information
vitaly-t authored Sep 29, 2024
1 parent 50b8ee1 commit 3e14f71
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 99 deletions.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Bug Report
about: New issues are for bug reports only. For everything else, use Discussions.
title: ''
labels: ''
assignees: ''

---

### Expected behavior


### Actual behavior


### Steps to reproduce


### Environment

* Version of sub-events:
* OS type (Linux/Windows/Mac):
* Version of Node.js:
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm install
- run: npm run compile
- run: npm run lint
- run: npm test
- run: npm run build
- run: npm run doc
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Strongly-Typed Events

[![Build Status](https://github.com/vitaly-t/sub-events/actions/workflows/ci.yml/badge.svg)](https://github.com/vitaly-t/sub-events/actions/workflows/ci.yml)

Lightweight, strongly-typed events, with monitored subscriptions.

* Documentation: [API] + [WiKi].
Expand Down
29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-events",
"version": "1.9.0",
"version": "1.9.1",
"description": "Lightweight, strongly-typed events, with monitored subscriptions.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand All @@ -11,7 +11,7 @@
"compile": "tsc -p src && tsc -p extras/src && tsc extras/deploy.ts && tsc -p test",
"doc": "typedoc ./src/index.ts",
"lint": "tslint --fix ./src/**/*.ts ./extras/src/*.ts ./test/**/*.ts",
"test": "nyc mocha -r ts-node/register test/**/*.spec.ts"
"test": "mocha --timeout 10000 --import=tsx test/**/*.spec.ts --exit"
},
"files": [
"dist/src",
Expand All @@ -28,7 +28,7 @@
},
"license": "MIT",
"engines": {
"node": ">=10.0.0"
"node": ">=18.0.0"
},
"bugs": {
"url": "https://github.com/vitaly-t/sub-events/issues"
Expand All @@ -41,20 +41,19 @@
"typescript"
],
"devDependencies": {
"@types/chai": "4.3.3",
"@types/chai-spies": "1.0.3",
"@types/mocha": "9.1.1",
"@types/node": "18.7.22",
"@types/chai": "5.0.0",
"@types/chai-spies": "1.0.6",
"@types/mocha": "10.0.8",
"@types/node": "22.7.4",
"browserify": "17.0.0",
"chai": "4.3.6",
"chai-spies": "1.0.0",
"mocha": "10.0.0",
"chai": "5.1.1",
"chai-spies": "1.1.0",
"mocha": "10.7.3",
"mocha-lcov-reporter": "1.3.0",
"nyc": "15.1.0",
"ts-node": "10.9.1",
"tslib": "2.4.0",
"tslib": "2.7.0",
"tslint": "6.1.3",
"typedoc": "0.20.37",
"typescript": "4.2.4"
"tsx": "4.19.1",
"typedoc": "0.26.7",
"typescript": "5.6.2"
}
}
20 changes: 9 additions & 11 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import {Private} from './utils';
const pp = new Private<EventConsumer, SubEvent<any>>();

/**
* ### class EventConsumer\<T = unknown, E extends SubEvent\<T\> = SubEvent\<T\>>
* Encapsulates an event object, in order to hide its methods {@link SubEvent.emit} and {@link SubEvent.cancelAll},
* so the event consumer can only receive the event, but cannot emit it, or cancel other subscriptions.
*
* Encapsulates an event object, in order to hide its methods [[emit]] and [[cancelAll]], so the event
* consumer can only receive the event, but cannot emit it, or cancel other subscriptions.
*
* It is a non-extendable class, with the same signature as [[SubEvent]], minus methods [[emit]] and [[cancelAll]].
* It is a non-extendable class, with the same signature as {@link SubEvent}, minus {@link SubEvent.emit emit} and {@link SubEvent.cancelAll cancelAll}.
*
* ```ts
* // Example of using EventConsumer inside a component.
Expand Down Expand Up @@ -53,42 +51,42 @@ export class EventConsumer<T = unknown, E extends SubEvent<T> = SubEvent<T>> {
}

/**
* Forwards into [[SubEvent.count]] of the contained event.
* Forwards into {@link SubEvent.count} of the contained event.
*/
get count(): number {
return pp.get(this).count;
}

/**
* Forwards into [[SubEvent.maxSubs]] of the contained event.
* Forwards into {@link SubEvent.maxSubs} of the contained event.
*/
get maxSubs(): number {
return pp.get(this).maxSubs;
}

/**
* Forwards into [[SubEvent.subscribe]] of the contained event.
* Forwards into {@link SubEvent.subscribe} of the contained event.
*/
subscribe(cb: SubFunction<T>, options?: ISubOptions): Subscription {
return pp.get(this).subscribe(cb, options);
}

/**
* Forwards into [[SubEvent.once]] of the contained event.
* Forwards into {@link SubEvent.once} of the contained event.
*/
once(cb: SubFunction<T>, options?: ISubOptions): Subscription {
return pp.get(this).once(cb, options);
}

/**
* Forwards into [[SubEvent.toPromise]] of the contained event.
* Forwards into {@link SubEvent.toPromise} of the contained event.
*/
toPromise(options?: { name?: string, timeout?: number }): Promise<T> {
return pp.get(this).toPromise(options);
}

/**
* Forwards into [[SubEvent.getStat]] of the contained event.
* Forwards into {@link SubEvent.getStat} of the contained event.
*/
getStat(options?: { minUse?: number }): ISubStat {
return pp.get(this).getStat(options);
Expand Down
18 changes: 8 additions & 10 deletions src/count.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IEmitOptions, IEventOptions, ISubscriber, SubEvent} from './event';

/**
* Represents a change in the number of subscriptions, as used with [[onCount]] event.
* Represents a change in the number of subscriptions, as used with {@link SubEventCount.onCount} event.
*/
export interface ISubCountChange {
/**
Expand All @@ -16,19 +16,17 @@ export interface ISubCountChange {
}

/**
* Constructor options for [[SubEventCount]] class.
* Constructor options for {@link SubEventCount} class.
*/
export interface ICountOptions<T> extends IEventOptions<T> {
/**
* Emit options for event [[onCount]].
* Emit options for event {@link SubEventCount.onCount}.
*/
emitOptions?: IEmitOptions;
}

/**
* ### class SubEventCount\<T = unknown\> extends SubEvent\<T\>
*
* Extends [[SubEvent]] with event [[onCount]], to observe the number of subscriptions.
* Extends {@link SubEvent} with event {@link onCount}, to observe the number of subscriptions.
*/
export class SubEventCount<T = unknown> extends SubEvent<T> {

Expand All @@ -44,7 +42,6 @@ export class SubEventCount<T = unknown> extends SubEvent<T> {
readonly onCount: SubEvent<ISubCountChange> = new SubEvent();

/**
* @constructor
* Event constructor.
*
* @param options
Expand All @@ -59,13 +56,13 @@ export class SubEventCount<T = unknown> extends SubEvent<T> {
/**
* Cancels all existing subscriptions for the event.
*
* It overrides the base implementation, to trigger event [[onCount]]
* It overrides the base implementation, to trigger event {@link onCount}
* when there was at least one subscription.
*
* @returns
* Number of subscriptions cancelled.
*
* @see [[cancel]]
* @see {@link Subscription.cancel}
*/
public cancelAll(): number {
const prevCount = this.count;
Expand All @@ -77,8 +74,9 @@ export class SubEventCount<T = unknown> extends SubEvent<T> {
}

/**
* Overrides base implementation, to trigger event [[onCount]] during
* Overrides base implementation, to trigger event {@link onCount} during
* `subscribe` and `cancel` calls.
*
* @hidden
*/
protected _createCancel(sub: ISubscriber<T>): () => void {
Expand Down
Loading

0 comments on commit 3e14f71

Please sign in to comment.