using 'immediate' instead of 'async'
prevent publishing undefined messages.
This commit is contained in:
parent
ada6c04359
commit
f32ac4ea7d
@ -1,13 +1,13 @@
|
||||
import { injectable } from 'inversify';
|
||||
import { BehaviorSubject, CompletionObserver, ErrorObserver, NextObserver, Observable, Subscription } from 'rxjs';
|
||||
import { generateId } from '../helpers/idMethods';
|
||||
import { callImmediate } from '../helpers/runtimeMethods';
|
||||
import { type } from 'os';
|
||||
|
||||
|
||||
export type waitForCallback<T> = (content?: T | null, sender?: string, timeStamp?: number | null, ...data) => boolean | Promise<boolean>;
|
||||
export interface nopeWaitForOpitions {
|
||||
testFirst?: boolean;
|
||||
subscriptionMode?: 'async' | 'sync';
|
||||
subscriptionMode?: 'immediate' | 'sync';
|
||||
triggerMode?: Array<'sub' | 'super' | 'direct'>;
|
||||
}
|
||||
|
||||
@ -41,9 +41,10 @@ export type pipe<T, K> = (scope: { [index: string]: any }, observable: Observabl
|
||||
* - function to publish values. (wrapper for next)
|
||||
* - enables performing a subscription with synced call or a immediate call.
|
||||
*/
|
||||
export class nopeObservable<T,S = T,G = T> {
|
||||
@injectable()
|
||||
export class nopeObservable<T, S = T, G = T> {
|
||||
|
||||
public observable: BehaviorSubject<G> = new BehaviorSubject<G>(null);
|
||||
public observable: BehaviorSubject<G> = new BehaviorSubject<G>(undefined);
|
||||
|
||||
public readonly id: string = generateId();
|
||||
|
||||
@ -67,7 +68,7 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
protected _args: any[] = [];
|
||||
protected _sender: string;
|
||||
protected _timeStamp: number;
|
||||
|
||||
|
||||
/**
|
||||
* Function to
|
||||
* @param value
|
||||
@ -98,7 +99,7 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
}
|
||||
}
|
||||
|
||||
protected _updateSenderAndTimestamp(sender: string | null = null, timestamp: number | null = null,){
|
||||
protected _updateSenderAndTimestamp(sender: string | null = null, timestamp: number | null = null,) {
|
||||
// Define a Sender if required
|
||||
if (sender === null) {
|
||||
sender = this.id;
|
||||
@ -143,7 +144,7 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
this.observable.next(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Function to Force an Update.
|
||||
* @param sender Sender, which initiated the Update
|
||||
@ -157,7 +158,7 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
/**
|
||||
* A Set containing the Subscriptions
|
||||
*/
|
||||
protected _subscriptions = new Set<() => void>();
|
||||
public _subscriptions = new Set<() => void>();
|
||||
|
||||
/**
|
||||
* Flag to Disable Publishing
|
||||
@ -210,7 +211,7 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
if (typeof observer === 'object') {
|
||||
_observer = {
|
||||
next: (data: G) => {
|
||||
if (active && observer.next) {
|
||||
if (active && data !== undefined && observer.next) {
|
||||
if (mode === 'immediate') {
|
||||
callImmediate(observer.next, data, this._sender, this._timeStamp, ..._this._args);
|
||||
} else {
|
||||
@ -232,7 +233,7 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
} else if (typeof observer === 'function') {
|
||||
_observer = {
|
||||
next: (data: G) => {
|
||||
if (active) {
|
||||
if (active && data !== undefined) {
|
||||
if (mode === 'immediate') {
|
||||
callImmediate(observer, data, this._sender, this._timeStamp, ..._this._args);
|
||||
} else {
|
||||
@ -240,10 +241,10 @@ export class nopeObservable<T,S = T,G = T> {
|
||||
}
|
||||
}
|
||||
},
|
||||
complete: () => {},
|
||||
error: (error) => {},
|
||||
complete: () => { },
|
||||
error: (error) => { },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a Subscription.
|
||||
const subscription = this.observable.subscribe(_observer);
|
||||
|
Loading…
Reference in New Issue
Block a user