mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Resolved #322: Creating an Observable by passing a JSON object in the constructor does not define the respective properties on the Observable object instance.
This commit is contained in:
@ -8,13 +8,32 @@ interface ListenerEntry {
|
||||
|
||||
export class Observable implements definition.Observable {
|
||||
public static propertyChangeEvent = "propertyChange";
|
||||
private _map: Map<string, Object>;
|
||||
|
||||
private _observers = {};
|
||||
|
||||
constructor(json?: any) {
|
||||
if (json) {
|
||||
this._map = new Map<string, Object>();
|
||||
var that = this;
|
||||
|
||||
var definePropertyFunc = function definePropertyFunc(propertyName) {
|
||||
Object.defineProperty(Observable.prototype, propertyName, {
|
||||
get: function () {
|
||||
return that._map.get(propertyName);
|
||||
},
|
||||
set: function (value) {
|
||||
that._map.set(propertyName, value);
|
||||
that.notify(that._createPropertyChangeData(propertyName, value));
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
};
|
||||
|
||||
for (var prop in json) {
|
||||
if (json.hasOwnProperty(prop)) {
|
||||
definePropertyFunc(prop);
|
||||
this.set(prop, json[prop]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user