@esmj/observable
Advanced tools
Comparing version 0.1.1 to 0.2.1
@@ -29,3 +29,3 @@ interface IObserverFunction { | ||
#private; | ||
pipe(...operations: any[]): any; | ||
pipe<T extends IObservable>(...operations: any[]): T; | ||
next(...rest: any[]): void; | ||
@@ -39,4 +39,4 @@ error(...rest: any[]): void; | ||
} | ||
declare function pipe<T>(...operations: ((operation: T) => T)[]): (any: T) => T; | ||
declare function pipe<T extends IObservable>(...operations: ((operation: T) => T)[]): (any: T) => T; | ||
export { IExtendable, IObservable, IObserver, IObserverFunction, IObserverObject, Observable, Observer, Subscription, pipe }; |
@@ -36,3 +36,3 @@ var __defProp = Object.defineProperty; | ||
var Observable = class { | ||
#observers = []; | ||
#observers = /* @__PURE__ */ new Set(); | ||
pipe(...operations) { | ||
@@ -42,3 +42,3 @@ return pipe(...operations)(this); | ||
next(...rest) { | ||
this.#observers.forEach((observer) => { | ||
Array.from(this.#observers).forEach((observer) => { | ||
typeof observer === "function" ? observer(...rest) : observer.next(...rest); | ||
@@ -48,3 +48,3 @@ }); | ||
error(...rest) { | ||
this.#observers.forEach((observer) => { | ||
Array.from(this.#observers).forEach((observer) => { | ||
observer?.error?.(...rest); | ||
@@ -55,3 +55,3 @@ this.unsubscribe(observer); | ||
complete(...rest) { | ||
this.#observers.forEach((observer) => { | ||
Array.from(this.#observers).forEach((observer) => { | ||
observer?.complete?.(...rest); | ||
@@ -62,3 +62,3 @@ this.unsubscribe(observer); | ||
subscribe(observer) { | ||
this.#observers.push(observer); | ||
this.#observers.add(observer); | ||
return { | ||
@@ -71,4 +71,3 @@ unsubscribe: () => { | ||
unsubscribe(observer) { | ||
const index = this.#observers.indexOf(observer); | ||
this.#observers.splice(index, 1); | ||
this.#observers.delete(observer); | ||
} | ||
@@ -75,0 +74,0 @@ }; |
{ | ||
"name": "@esmj/observable", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"description": "Tiny observable library for other extensibility", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -20,3 +20,3 @@ # Observable | ||
```javascript | ||
import { Observable, IObservable, IObserver } from '@esmj/monitor'; | ||
import { Observable, IObservable, IObserver } from '@esmj/observable'; | ||
@@ -66,2 +66,2 @@ const observer: IObserver = { | ||
##### observer | ||
Type: `() => void | { ?next: () => void, error?: () => void, complete?: () => void}` | ||
Type: `() => void | { ?next: () => void, error?: () => void, complete?: () => void}` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9742
66
176