Implemented Observable constructor that accepts JSON objects.

This commit is contained in:
Rossen Hristov
2015-03-24 12:20:47 +02:00
parent 8601a9ee75
commit 7d15ae8249
3 changed files with 37 additions and 0 deletions

View File

@@ -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".
*/

View File

@@ -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);
}