NotifyPropertyChange on Nativescript

If you like me are developing apps with nativescript core with typescript, probably know the PropertyChange event behind the MVVM (Yes, I love NativeScript core with TS because reminds me to my love for WPF/UWP development on Windows).

How on Windows, your class must implement the INotifyPropertyChange interface, in Nativescript specific case you just need to extends the Observable class.

Here how you can notify that a property is changed (we are assuming that we have a ViewModel with the property “Clicked” ad “ClickedTitle” in it.

public Clicked: number = 0;
public ClickedTitle: string = "";
// note that this is an attribute, not a property
public UpdateUI()
   this.Clicked = this.Clicked++;
   this.ClickedTitle = "You have clicked " + this.Clicked + " times";
   this.notifyPropertyChange("Clicked", this.Clicked);
   this.notifyPropertyChange("ClickedTitle", this.ClickedTitle);
Continue reading “NotifyPropertyChange on Nativescript”

Typescript object VS javascript object

The use of Typescript is amazing for web/app development, however we must remember that Typescript is a javascript’s superset and it will be transpiled in pure js with all limitation of the case.

Let’s see a courios case I’ve faced today.

export class User
   // class attributes
   public name: string = "";
   public surname: string = "";
   // class properties
   public get FullName(): string
     return + " " + this.surname;
   public SayHello()
     console.log("Hello " + this.FullName);

How you can see on the code block above, we have a class named User with two attributes, Name and Surname, and a readonly property, FullName.

function ConvertObject<T>(arg: any): T
    const result: T = {} as T;
    return Object.assign(result, arg) as T;
Continue reading “Typescript object VS javascript object”