From 55c747dab4a0db126baa9693b57836963b4b334d Mon Sep 17 00:00:00 2001 From: Kingcean Tuan Date: Tue, 15 Sep 2020 22:36:05 +0800 Subject: [PATCH] Optimize value controller. --- dist/index.d.ts | 13 +++++++++++- dist/index.js | 4 ++-- package-lock.json | 52 ++++++++++++++------------------------------- package.json | 4 ++-- src/objects.ts | 2 ++ src/values.ts | 24 ++++++++++++++++++++- test/dist/engine.js | 1 + 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index f01a882..3165a6f 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1352,12 +1352,13 @@ declare namespace DataSense { */ class ValueClient extends ValueObservable { private readonly _setter; + private readonly _forceUpdate; private readonly _sendNotify; private readonly _registerRequestHandler; /** * Initializes a new instance of the ValueClient class. */ - constructor(defaultValue: T, modifier: (setter: ValueModifierContract) => void, setter: (value: T, message?: FireInfoContract | string) => ChangedInfo, sendNotify: (data: any, message?: FireInfoContract | string) => void, registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract, value: any) => void) => boolean, additionalEvents: ValueFurtherEventsContract); + constructor(defaultValue: T, modifier: (setter: ValueModifierContract) => void, setter: (value: T, message?: FireInfoContract | string) => ChangedInfo, sendNotify: (data: any, message?: FireInfoContract | string) => void, registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract, value: any) => void) => boolean, additionalEvents: ValueFurtherEventsContract, forceUpdate?: (message?: FireInfoContract | string) => void); /** * Sets value. * @param value The value of the property to set. @@ -1384,6 +1385,11 @@ declare namespace DataSense { * @param callbackfn A function will be called on subscribed. */ setSubscribe(value: SubscriberContract, message?: FireInfoContract | string, callbackfn?: (ev: ChangedInfo, message: FireInfoContract) => void, thisArg?: any): SubscriberResultContract; + /** + * Forces to notify the update event. + * @param message A message for the setting event. + */ + forceUpdate(message?: FireInfoContract | string): void; /** * Send a notification. * @param data The data. @@ -1449,6 +1455,11 @@ declare namespace DataSense { * @param callbackfn A function will be called on subscribed. */ setSubscribe(value: SubscriberContract, message?: FireInfoContract | string, callbackfn?: (ev: ChangedInfo, message: FireInfoContract) => void, thisArg?: any): SubscriberResultContract; + /** + * Forces to notify the update event. + * @param message A message for the setting event. + */ + forceUpdate(message?: FireInfoContract | string): void; /** * Registers a handler to respond the request message. * @param type The request type. diff --git a/dist/index.js b/dist/index.js index e1a2dc5..758920d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -// datasense -var DataSense,__spreadArrays=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;tn.span)||(p=1),a=new Date,!(null!=n.minCount&&pn.maxCount)){if(s)if("debounce"===n.mergeMode)clearTimeout(s);else if("mono"===n.mergeMode)return;null==n.delay||!1===n.delay?o(e):!0===n.delay?s=setTimeout(function(){o(e)},0):"number"==typeof n.delay&&(s=setTimeout(function(){o(e)},n.delay))}}}e.HitTask=t}(DataSense||(DataSense={})),function(p){var r=(f.prototype.pushDisposable=function(){for(var e,t=[],n=0;nn.span)||(p=1),a=new Date,!(null!=n.minCount&&pn.maxCount)){if(s)if("debounce"===n.mergeMode)clearTimeout(s);else if("mono"===n.mergeMode)return;null==n.delay||!1===n.delay?o(e):!0===n.delay?s=setTimeout(function(){o(e)},0):"number"==typeof n.delay&&(s=setTimeout(function(){o(e)},n.delay))}}}e.HitTask=t}(DataSense||(DataSense={})),function(p){var r=(f.prototype.pushDisposable=function(){for(var e,t=[],n=0;n { + this.forceUpdateProp(key, message); }); client.pushDisposable(token); return client; diff --git a/src/values.ts b/src/values.ts index 805b6aa..89428c0 100644 --- a/src/values.ts +++ b/src/values.ts @@ -376,6 +376,7 @@ export class ValueObservable implements DisposableArrayContract { */ export class ValueClient extends ValueObservable { private readonly _setter: (value: T, message?: FireInfoContract | string) => ChangedInfo; + private readonly _forceUpdate: (message?: FireInfoContract | string) => void; private readonly _sendNotify: (data: any, message?: FireInfoContract | string) => void; private readonly _registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract, value: any) => void) => boolean; @@ -388,7 +389,8 @@ export class ValueClient extends ValueObservable { setter: (value: T, message?: FireInfoContract | string) => ChangedInfo, sendNotify: (data: any, message?: FireInfoContract | string) => void, registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract, value: any) => void) => boolean, - additionalEvents: ValueFurtherEventsContract + additionalEvents: ValueFurtherEventsContract, + forceUpdate?: (message?: FireInfoContract | string) => void ) { let h = (acc: ValueObservableAccessorContract) => { acc.set(defaultValue); @@ -400,6 +402,7 @@ export class ValueClient extends ValueObservable { if (typeof setter === "function") this._setter = setter; if (typeof sendNotify === "function") this._sendNotify = sendNotify; if (typeof registerRequestHandler === "function") this._registerRequestHandler = registerRequestHandler; + if (typeof forceUpdate === "function") this._forceUpdate = forceUpdate; } /** @@ -447,6 +450,15 @@ export class ValueClient extends ValueObservable { }, value, message, callbackfn, thisArg); } + /** + * Forces to notify the update event. + * @param message A message for the setting event. + */ + public forceUpdate(message?: FireInfoContract | string) { + if (typeof this._forceUpdate !== "function") return; + this._forceUpdate(message); + } + /** * Send a notification. * @param data The data. @@ -554,6 +566,14 @@ export class ValueController extends ValueObservable { }, value, message, callbackfn, thisArg); } + /** + * Forces to notify the update event. + * @param message A message for the setting event. + */ + public forceUpdate(message?: FireInfoContract | string) { + this._accessor.forceUpdate(message); + } + /** * Registers a handler to respond the request message. * @param type The request type. @@ -635,6 +655,8 @@ export class ValueController extends ValueObservable { notifyReceived: this.notifyReceived.createObservable(), sendRequest, sendBroadcast + }, (message?) => { + this.forceUpdate(message); }); client.pushDisposable(token); this.pushDisposable(client); diff --git a/test/dist/engine.js b/test/dist/engine.js index 0d95223..24394ca 100644 --- a/test/dist/engine.js +++ b/test/dist/engine.js @@ -1,5 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +exports.assert = exports.run = exports.create = void 0; let assertCount = 0; function create(name) { let list = [];