Last active
February 23, 2018 20:51
-
-
Save AlbertoDePena/876071b506a3434b2b2d038703cc956c to your computer and use it in GitHub Desktop.
NativeScript extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from "data/observable"; | |
export abstract class ObservableBase extends Observable { | |
constructor() { super(); } | |
public getPropertyName<PropertyName extends keyof this>(propertyName: PropertyName) { return propertyName; } | |
} | |
export function getProperty<T extends Observable, PropertyName extends keyof T>(observable: T, propertyName: PropertyName) { | |
return observable.get(propertyName); | |
} | |
export function setProperty<T extends Observable, PropertyName extends keyof T> | |
(observable: T, propertyName: PropertyName, propertyValue: T[PropertyName]) { | |
observable.set(propertyName, propertyValue); | |
} | |
export function ObservableProperty() { | |
return (target: Observable, propertyName: string) => { | |
Object.defineProperty(target, propertyName, { | |
get(): any { | |
return this["_" + propertyName]; | |
}, | |
set(value: any): void { | |
if (this["_" + propertyName] === value) { return; } | |
this["_" + propertyName] = value; | |
this.notifyPropertyChange(propertyName, value); | |
}, | |
enumerable: true, | |
configurable: true | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment