DigitMagazine

Hello World Model for Nativescript

Oct 19th, 2016
116
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None
  1. import {Observable} from ‘data/observable’;
  2. export class HelloWorldModel extends Observable {
  3. private _counter: number;
  4. private _message: string;
  5. constructor() {
  6. super();
  7. // Initialize default values.
  8. this._counter = 42;
  9. this.updateMessage();
  10. }
  11. get message(): string {
  12. returnthis._message;
  13. }
  14. set message(value: string) {
  15. if (this._message !== value) {
  16. this._message = value;
  17. this.notifyPropertyChange(‘message’, value)
  18. }
  19. }
  20. publiconTap() {
  21. this._counter--;
  22. this.updateMessage();
  23. }
  24. privateupdateMessage() {
  25. if (this._counter<= 0) {
  26. this.message = ‘Hoorraaay! You unlocked the NativeScript clicker achievement!’;
  27. } else {
  28. this.message = `${this._counter} taps left`;
  29. }
  30. }
  31. }
RAW Paste Data Copied