mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: setProperty on Observable (#8521)
* feat: setProperty on Observable * refactor: add missing whitespace Co-Authored-By: Vasil Trifonov <v.trifonov@gmail.com> Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
This commit is contained in:
@@ -1503,6 +1503,8 @@ export class Observable {
|
||||
removeEventListener(eventNames: string, callback?: any, thisArg?: any);
|
||||
|
||||
set(name: string, value: any): void;
|
||||
|
||||
setProperty(name: string, value: any): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
@@ -2425,10 +2427,11 @@ export class TabViewItem extends ViewBase {
|
||||
|
||||
// @public
|
||||
export interface TapGestureEventData extends GestureEventData {
|
||||
getPointerCount(): number;
|
||||
getPointerCount(): number;
|
||||
getX(): number;
|
||||
getY(): number;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @public
|
||||
export interface Template {
|
||||
|
||||
@@ -129,6 +129,11 @@ export class Observable {
|
||||
*/
|
||||
set(name: string, value: any): void;
|
||||
|
||||
/**
|
||||
* Updates the specified property with the provided value and raises a property change event and a specific change event based on the property name.
|
||||
*/
|
||||
setProperty(name: string, value: any): void;
|
||||
|
||||
/**
|
||||
* Gets the value of the specified property.
|
||||
*/
|
||||
|
||||
@@ -57,6 +57,22 @@ export class Observable implements ObservableDefinition {
|
||||
this.notifyPropertyChange(name, newValue, oldValue);
|
||||
}
|
||||
|
||||
public setProperty(name: string, value: any) {
|
||||
const oldValue = this[name];
|
||||
if (this[name] === value) {
|
||||
return;
|
||||
}
|
||||
this[name] = value;
|
||||
this.notifyPropertyChange(name, value, oldValue);
|
||||
|
||||
const specificPropertyChangeEventName = name + "Change";
|
||||
if (this.hasListeners(specificPropertyChangeEventName)) {
|
||||
const eventData = this._createPropertyChangeData(name, value, oldValue);
|
||||
eventData.eventName = specificPropertyChangeEventName;
|
||||
this.notify(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public on(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
|
||||
this.addEventListener(eventNames, callback, thisArg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user