added support for Object.observe in supported browsers

This commit is contained in:
DadaMonad
2014-12-02 09:50:21 +00:00
parent d4bb2dc173
commit 9b582fc795
38 changed files with 741 additions and 82 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -61,6 +61,10 @@
return _results;
};
Operation.prototype.deleteAllListeners = function() {
return this.event_listeners = [];
};
Operation.prototype.callEvent = function() {
return this.forwardEvent.apply(this, [this].concat(__slice.call(arguments)));
};
@@ -97,7 +101,8 @@
};
Operation.prototype.cleanup = function() {
return HB.removeOperation(this);
HB.removeOperation(this);
return this.deleteAllListeners();
};
Operation.prototype.setParent = function(parent) {

File diff suppressed because one or more lines are too long

View File

@@ -87,25 +87,74 @@
};
JsonType.prototype.toJson = function() {
var json, name, o, val;
val = this.val();
json = {};
for (name in val) {
o = val[name];
if (o === null) {
json[name] = o;
} else if (o.constructor === {}.constructor) {
json[name] = this.val(name).toJson();
} else if (o instanceof types.Operation) {
while (o instanceof types.Operation) {
o = o.val();
var json, name, o, that, val;
if ((this.bound_json == null) || (Object.observe == null) || true) {
val = this.val();
json = {};
for (name in val) {
o = val[name];
if (o === null) {
json[name] = o;
} else if (o.constructor === {}.constructor) {
json[name] = this.val(name).toJson();
} else if (o instanceof types.Operation) {
while (o instanceof types.Operation) {
o = o.val();
}
json[name] = o;
} else {
json[name] = o;
}
json[name] = o;
} else {
json[name] = o;
}
this.bound_json = json;
if ((Object.observe != null) && false) {
that = this;
Object.observe(this.bound_json, function(events) {
var event, _i, _len, _results;
_results = [];
for (_i = 0, _len = events.length; _i < _len; _i++) {
event = events[_i];
if (event.type === "add" || (event.type = "update")) {
_results.push(that.val(event.name, event.object[event.name]));
} else {
_results.push(void 0);
}
}
return _results;
});
that.on('change', function(event_name, property_name, op) {
var notifier, oldVal;
if (this === that) {
notifier = Object.getNotifier(that.bound_json);
oldVal = that.bound_json[property_name];
if (oldVal != null) {
notifier.performChange('update', function() {
return that.bound_json[property_name] = that.val(property_name);
}, that.bound_json);
return notifier.notify({
object: that.bound_json,
type: 'update',
name: property_name,
oldValue: oldVal,
changed_by: op.creator
});
} else {
notifier.performChange('add', function() {
return that.bound_json[property_name] = that.val(property_name);
}, that.bound_json);
return notifier.notify({
object: that.bound_json,
type: 'add',
name: property_name,
oldValue: oldVal,
changed_by: op.creator
});
}
}
});
}
}
return json;
return this.bound_json;
};
JsonType.prototype.setReplaceManager = function(replace_manager) {

File diff suppressed because one or more lines are too long

View File

@@ -255,7 +255,7 @@
}
});
addPropertyListener = function(event, op) {
repl_manager.deleteListener('addProperty', addPropertyListener);
repl_manager.deleteListener('insert', addPropertyListener);
return repl_manager.parent.callEvent('addProperty', property_name, op);
};
this.on('insert', addPropertyListener);
@@ -318,6 +318,9 @@
Replaceable.prototype.applyDelete = function() {
if (this.content != null) {
if (this.next_cl.type !== "Delimiter") {
this.content.deleteAllListeners();
}
this.content.applyDelete();
this.content.dontSync();
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long