mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Implemented Observable constructor that accepts JSON objects.
This commit is contained in:
6
data/observable/observable.d.ts
vendored
6
data/observable/observable.d.ts
vendored
@@ -44,6 +44,12 @@ declare module "data/observable" {
|
||||
* Observable is used when you want to be notified when a change occurs. Use on/off methods to add/remove listener.
|
||||
*/
|
||||
class Observable {
|
||||
|
||||
/**
|
||||
* Creates an Observable instance and sets its properties accroding to the supplied JSON object.
|
||||
*/
|
||||
constructor(json?: any);
|
||||
|
||||
/**
|
||||
* Gets the name of the constructor function for this instance. E.g. for a Button class this will return "Button".
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,16 @@ export module knownEvents {
|
||||
export class Observable implements definition.Observable {
|
||||
private _observers = {};
|
||||
|
||||
constructor(json?: any) {
|
||||
if (json) {
|
||||
for (var prop in json) {
|
||||
if (json.hasOwnProperty(prop)) {
|
||||
this.set(prop, json[prop]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get typeName(): string {
|
||||
return types.getClass(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user