Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions api-reports/NativeScript.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -2425,10 +2427,11 @@ export class TabViewItem extends ViewBase {

// @public
export interface TapGestureEventData extends GestureEventData {
getPointerCount(): number;
getPointerCount(): number;
Comment thread
rigor789 marked this conversation as resolved.
getX(): number;
getY(): number;
}

Comment thread
rigor789 marked this conversation as resolved.
}

// @public
export interface Template {
Expand Down
5 changes: 5 additions & 0 deletions nativescript-core/data/observable/observable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
16 changes: 16 additions & 0 deletions nativescript-core/data/observable/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
rigor789 marked this conversation as resolved.
this.notifyPropertyChange(name, value, oldValue);

const specificPropertyChangeEventName = name + "Change";
Comment thread
rigor789 marked this conversation as resolved.
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);
}
Expand Down