Skip to content

Commit

Permalink
Optimize value controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcean committed Sep 15, 2020
1 parent da35b2a commit 55c747d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
13 changes: 12 additions & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1352,12 +1352,13 @@ declare namespace DataSense {
*/
class ValueClient<T> extends ValueObservable<T> {
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<T>) => void, setter: (value: T, message?: FireInfoContract | string) => ChangedInfo<T>, sendNotify: (data: any, message?: FireInfoContract | string) => void, registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract<T>, value: any) => void) => boolean, additionalEvents: ValueFurtherEventsContract);
constructor(defaultValue: T, modifier: (setter: ValueModifierContract<T>) => void, setter: (value: T, message?: FireInfoContract | string) => ChangedInfo<T>, sendNotify: (data: any, message?: FireInfoContract | string) => void, registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract<T>, value: any) => void) => boolean, additionalEvents: ValueFurtherEventsContract, forceUpdate?: (message?: FireInfoContract | string) => void);
/**
* Sets value.
* @param value The value of the property to set.
Expand All @@ -1384,6 +1385,11 @@ declare namespace DataSense {
* @param callbackfn A function will be called on subscribed.
*/
setSubscribe(value: SubscriberContract<T>, message?: FireInfoContract | string, callbackfn?: (ev: ChangedInfo<T>, 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.
Expand Down Expand Up @@ -1449,6 +1455,11 @@ declare namespace DataSense {
* @param callbackfn A function will be called on subscribed.
*/
setSubscribe(value: SubscriberContract<T>, message?: FireInfoContract | string, callbackfn?: (ev: ChangedInfo<T>, 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.
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

52 changes: 16 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datasense",
"version": "1.1.0",
"version": "1.2.0",
"description": "A set of powerful utilities and classes for accessing and observing data.",
"main": "index.js",
"types": "./index.d.ts",
Expand Down Expand Up @@ -31,6 +31,6 @@
"gulp-sourcemaps": "^2.6.5",
"gulp-typescript": "^5.0.1",
"gulp-uglify": "^3.0.2",
"typescript": "^3.9.6"
"typescript": "^4.0.2"
}
}
2 changes: 2 additions & 0 deletions src/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,8 @@ export class PropsController extends PropsObservable {
notifyReceived: this.propNotifyReceived.createSingleObservable(key),
sendRequest,
sendBroadcast
}, (message?) => {
this.forceUpdateProp(key, message);
});
client.pushDisposable(token);
return client;
Expand Down
24 changes: 23 additions & 1 deletion src/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export class ValueObservable<T> implements DisposableArrayContract {
*/
export class ValueClient<T> extends ValueObservable<T> {
private readonly _setter: (value: T, message?: FireInfoContract | string) => ChangedInfo<T>;
private readonly _forceUpdate: (message?: FireInfoContract | string) => void;
private readonly _sendNotify: (data: any, message?: FireInfoContract | string) => void;
private readonly _registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract<T>, value: any) => void) => boolean;

Expand All @@ -388,7 +389,8 @@ export class ValueClient<T> extends ValueObservable<T> {
setter: (value: T, message?: FireInfoContract | string) => ChangedInfo<T>,
sendNotify: (data: any, message?: FireInfoContract | string) => void,
registerRequestHandler: (type: string, h: (owner: SimpleValueAccessorContract<T>, value: any) => void) => boolean,
additionalEvents: ValueFurtherEventsContract
additionalEvents: ValueFurtherEventsContract,
forceUpdate?: (message?: FireInfoContract | string) => void
) {
let h = (acc: ValueObservableAccessorContract<T>) => {
acc.set(defaultValue);
Expand All @@ -400,6 +402,7 @@ export class ValueClient<T> extends ValueObservable<T> {
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;
}

/**
Expand Down Expand Up @@ -447,6 +450,15 @@ export class ValueClient<T> extends ValueObservable<T> {
}, 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.
Expand Down Expand Up @@ -554,6 +566,14 @@ export class ValueController<T> extends ValueObservable<T> {
}, 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.
Expand Down Expand Up @@ -635,6 +655,8 @@ export class ValueController<T> extends ValueObservable<T> {
notifyReceived: this.notifyReceived.createObservable(),
sendRequest,
sendBroadcast
}, (message?) => {
this.forceUpdate(message);
});
client.pushDisposable(token);
this.pushDisposable(client);
Expand Down
1 change: 1 addition & 0 deletions test/dist/engine.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down

0 comments on commit 55c747d

Please sign in to comment.