Using deepEqual in observables.

This commit is contained in:
Martin Karkowski 2022-02-01 12:59:27 +01:00
parent eda224bd55
commit 2cd0ff596f
12 changed files with 32 additions and 18 deletions

View File

@ -1 +1 @@
1.0.18 1.0.21

View File

@ -31,12 +31,12 @@ import {
INopeRpcManager, INopeRpcManager,
INopeStatusInfo, INopeStatusInfo,
TValidAsssignmentChecker, TValidAsssignmentChecker,
ValidSelectorFunction ValidSelectorFunction,
} from "../../types/nope"; } from "../../types/nope";
import { import {
INopeInstanceManager, INopeInstanceManager,
TConstructorCallback, TConstructorCallback,
TGenerateWrapperCallback TGenerateWrapperCallback,
} from "../../types/nope/nopeInstanceManager.interface"; } from "../../types/nope/nopeInstanceManager.interface";
import { NopeConnectivityManager } from "../ConnectivityManager"; import { NopeConnectivityManager } from "../ConnectivityManager";
import { NopeRpcManager } from "../RpcManager/NopeRpcManager"; import { NopeRpcManager } from "../RpcManager/NopeRpcManager";

View File

@ -1,9 +1,6 @@
/** /**
* @author Martin Karkowski * @author Martin Karkowski
* @email m.karkowski@zema.de * @email m.karkowski@zema.de
* @create date 2021-11-13 14:13:06
* @modify date 2021-11-13 14:13:06
* @desc [description]
*/ */
import { BehaviorSubject, ReplaySubject, Subject } from "rxjs"; import { BehaviorSubject, ReplaySubject, Subject } from "rxjs";

View File

@ -5,6 +5,7 @@
import * as arrays from "./arrayMethods"; import * as arrays from "./arrayMethods";
import * as async from "./async"; import * as async from "./async";
import * as subject from "./getSubject";
import * as ids from "./idMethods"; import * as ids from "./idMethods";
import * as json from "./jsonMethods"; import * as json from "./jsonMethods";
import * as schema from "./jsonSchemaMethods"; import * as schema from "./jsonSchemaMethods";
@ -18,6 +19,7 @@ import * as strings from "./stringMethods";
export * from "./arrayMethods"; export * from "./arrayMethods";
export * from "./async"; export * from "./async";
export * from "./getSubject";
export * from "./idMethods"; export * from "./idMethods";
export * from "./jsonMethods"; export * from "./jsonMethods";
export * from "./jsonSchemaMethods"; export * from "./jsonSchemaMethods";
@ -41,4 +43,5 @@ export {
strings, strings,
pathes, pathes,
runtime, runtime,
subject,
}; };

View File

@ -7,6 +7,7 @@
*/ */
export const SPLITCHAR = "/"; export const SPLITCHAR = "/";
import { deepEqual as _deepEqual } from "assert";
const _sentinel = new Object(); const _sentinel = new Object();
@ -510,7 +511,20 @@ export function deepClone<T>(obj: T): T {
} }
} }
// export const deepEqual: (a: any, b: any) => boolean = require('deep-equal'); /**
* Compares deep a and b (using assert)
* @param a Object A
* @param b Object B
* @returns The Result
*/
export function deepEqual<T>(a: T, b: T): boolean {
try {
_deepEqual(a, b);
return true;
} catch (e) {
return false;
}
}
/** /**
* Function to adapt the Object and only return a specific amount of elements. * Function to adapt the Object and only return a specific amount of elements.

View File

@ -10,7 +10,7 @@ import {
getPropertyPath, getPropertyPath,
isEmitterPathCorrect, isEmitterPathCorrect,
isMethodPathCorrect, isMethodPathCorrect,
isPropertyPathCorrect isPropertyPathCorrect,
} from "../helpers/dispatcherPathes"; } from "../helpers/dispatcherPathes";
import { deepClone } from "../helpers/objectMethods"; import { deepClone } from "../helpers/objectMethods";
import { getNopeLogger } from "../logger/getLogger"; import { getNopeLogger } from "../logger/getLogger";
@ -21,7 +21,7 @@ import {
IFunctionOptions, IFunctionOptions,
INopeModule, INopeModule,
INopeModuleDescription, INopeModuleDescription,
IVersion IVersion,
} from "../types/nope/nopeModule.interface"; } from "../types/nope/nopeModule.interface";
import { INopeObservable } from "../types/nope/nopeObservable.interface"; import { INopeObservable } from "../types/nope/nopeObservable.interface";

View File

@ -7,7 +7,7 @@ import { inject, injectable } from "inversify";
import { INopeCore } from "../index.browser"; import { INopeCore } from "../index.browser";
import { import {
DISPATCHER_INSTANCE, DISPATCHER_INSTANCE,
OBSERVABLE_FACTORY OBSERVABLE_FACTORY,
} from "../symbols/identifiers"; } from "../symbols/identifiers";
import { INopeObservable } from "../types/nope/nopeObservable.interface"; import { INopeObservable } from "../types/nope/nopeObservable.interface";
import { NopeGenericWrapper } from "./GenericWrapper"; import { NopeGenericWrapper } from "./GenericWrapper";

View File

@ -11,7 +11,7 @@ import { INopeDispatcher } from "../types/nope/nopeDispatcher.interface";
import { import {
IEventOptions, IEventOptions,
IFunctionOptions, IFunctionOptions,
INopeModuleDescription INopeModuleDescription,
} from "../types/nope/nopeModule.interface"; } from "../types/nope/nopeModule.interface";
import { INopeObservable } from "../types/nope/nopeObservable.interface"; import { INopeObservable } from "../types/nope/nopeObservable.interface";
import { INopePromise } from "../types/nope/nopePromise.interface"; import { INopePromise } from "../types/nope/nopePromise.interface";

View File

@ -8,4 +8,3 @@ export { NopeBaseModule } from "./BaseModule";
export { InjectableNopeBaseModule } from "./BaseModule.injectable"; export { InjectableNopeBaseModule } from "./BaseModule.injectable";
export { NopeGenericWrapper } from "./GenericWrapper"; export { NopeGenericWrapper } from "./GenericWrapper";
export { InjectableNopeGenericWrapper } from "./GenericWrapper.injectable"; export { InjectableNopeGenericWrapper } from "./GenericWrapper.injectable";

View File

@ -7,6 +7,7 @@ import { BehaviorSubject } from "rxjs";
import { NopeEventEmitter } from "../eventEmitter/nopeEventEmitter"; import { NopeEventEmitter } from "../eventEmitter/nopeEventEmitter";
import { TSubjectOptions } from "../helpers/getSubject"; import { TSubjectOptions } from "../helpers/getSubject";
import { generateId } from "../helpers/idMethods"; import { generateId } from "../helpers/idMethods";
import { deepEqual } from "../helpers/objectMethods";
import { getNopeLogger } from "../logger/getLogger"; import { getNopeLogger } from "../logger/getLogger";
import { import {
IEventAdditionalData, IEventAdditionalData,
@ -15,7 +16,7 @@ import {
INopeObserver, INopeObserver,
INopePartialObserver, INopePartialObserver,
INopeSubscriptionOptions, INopeSubscriptionOptions,
IObservableType IObservableType,
} from "../types/nope/index"; } from "../types/nope/index";
const logger = getNopeLogger("obervable"); const logger = getNopeLogger("obervable");
@ -79,10 +80,10 @@ export class NopeObservable<
const valueToPublish = this.getContent(); const valueToPublish = this.getContent();
/** Publish the Data */ // Publish the Data, but only if they are different (deeply)
if ( if (
!this.disablePublishing && !this.disablePublishing &&
(options.forced || this._emitter.value?.value !== valueToPublish) (options.forced || !deepEqual(this._emitter.value?.value, valueToPublish))
) { ) {
return this._publish(valueToPublish, options); return this._publish(valueToPublish, options);
} }

View File

@ -9,13 +9,13 @@
import { INopeCore, INopeModule } from "."; import { INopeCore, INopeModule } from ".";
import { import {
IAvailableInstancesMsg, IAvailableInstancesMsg,
IInstanceCreationMsg IInstanceCreationMsg,
} from "./nopeCommunication.interface"; } from "./nopeCommunication.interface";
import { INopeStatusInfo } from "./nopeConnectivityManager.interface"; import { INopeStatusInfo } from "./nopeConnectivityManager.interface";
import { IMapBasedMergeData } from "./nopeHelpers.interface"; import { IMapBasedMergeData } from "./nopeHelpers.interface";
import { import {
IGenericNopeModule, IGenericNopeModule,
INopeModuleDescription INopeModuleDescription,
} from "./nopeModule.interface"; } from "./nopeModule.interface";
import { INopeObservable } from "./nopeObservable.interface"; import { INopeObservable } from "./nopeObservable.interface";
import { ValidSelectorFunction } from "./nopeRpcManager.interface"; import { ValidSelectorFunction } from "./nopeRpcManager.interface";

View File

@ -1,6 +1,6 @@
{ {
"name": "nope", "name": "nope",
"version": "1.0.18", "version": "1.0.21",
"description": "NoPE Runtime for Nodejs. For Browser-Support please use nope-browser", "description": "NoPE Runtime for Nodejs. For Browser-Support please use nope-browser",
"files": [ "files": [
"dist-nodejs/**/*", "dist-nodejs/**/*",