diff options
author | Nivesh Rajbhandari | 2012-04-18 13:49:26 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-18 13:49:26 -0700 |
commit | e6bdea62cff68837239c1be579926693c1aa7bdf (patch) | |
tree | bddf63c8b1fc493ec64aca642b8887321674bb16 /node_modules/montage/core/event/binding.js | |
parent | 7b3ef287f248c07602aefa3ba2cc907e0d16493a (diff) | |
parent | 2e04af953463643791f6362bd8ef4c6ba190abfa (diff) | |
download | ninja-e6bdea62cff68837239c1be579926693c1aa7bdf.tar.gz |
Merge branch 'refs/heads/ninja-internal' into EricMerge
Diffstat (limited to 'node_modules/montage/core/event/binding.js')
-rwxr-xr-x | node_modules/montage/core/event/binding.js | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/node_modules/montage/core/event/binding.js b/node_modules/montage/core/event/binding.js index 21b40609..709a5d85 100755 --- a/node_modules/montage/core/event/binding.js +++ b/node_modules/montage/core/event/binding.js | |||
@@ -18,6 +18,7 @@ var Montage = require("montage").Montage, | |||
18 | ChangeTypes = require("core/event/mutable-event").ChangeTypes, | 18 | ChangeTypes = require("core/event/mutable-event").ChangeTypes, |
19 | Serializer = require("core/serializer").Serializer, | 19 | Serializer = require("core/serializer").Serializer, |
20 | Deserializer = require("core/deserializer").Deserializer, | 20 | Deserializer = require("core/deserializer").Deserializer, |
21 | logger = require("core/logger").logger("binding"); | ||
21 | defaultEventManager = require("core/event/event-manager").defaultEventManager, | 22 | defaultEventManager = require("core/event/event-manager").defaultEventManager, |
22 | AT_TARGET = 2, | 23 | AT_TARGET = 2, |
23 | UNDERSCORE = "_"; | 24 | UNDERSCORE = "_"; |
@@ -1184,11 +1185,14 @@ var BindingDescriptor = exports.BindingDescriptor = Montage.create(Montage, /** | |||
1184 | }, | 1185 | }, |
1185 | 1186 | ||
1186 | serializeSelf: {value: function(serializer) { | 1187 | serializeSelf: {value: function(serializer) { |
1187 | serializer.setReference("boundObject", this.boundObject); | 1188 | var serialization = {}; |
1188 | serializer.set("boundObjectPropertyPath", this.boundObjectPropertyPath); | 1189 | |
1189 | serializer.set("oneway", this.oneway); | 1190 | serializer.addObjectReference(this.boundObject); |
1190 | serializer.set("deferred", this.deferred); | 1191 | serialization[this.oneway ? "<-" : "<<->"] = "@" + serializer.getObjectLabel(this.boundObject) + "." + this.boundObjectPropertyPath; |
1191 | serializer.set("converter", this.converter); | 1192 | serialization.deferred = this.deferred; |
1193 | serialization.converter = this.converter; | ||
1194 | |||
1195 | return serialization; | ||
1192 | }} | 1196 | }} |
1193 | }); | 1197 | }); |
1194 | 1198 | ||
@@ -1200,10 +1204,36 @@ Serializer.defineSerializationUnit("bindings", function(object) { | |||
1200 | } | 1204 | } |
1201 | }); | 1205 | }); |
1202 | 1206 | ||
1203 | Deserializer.defineDeserializationUnit("bindings", function(object, bindings) { | 1207 | Deserializer.defineDeserializationUnit("bindings", function(object, bindings, deserializer) { |
1204 | var sourcePath; | 1208 | for (var sourcePath in bindings) { |
1205 | for (sourcePath in bindings) { | 1209 | var binding = bindings[sourcePath], |
1206 | Object.defineBinding(object, sourcePath, bindings[sourcePath]); | 1210 | dotIndex; |
1211 | |||
1212 | if (!("boundObject" in binding)) { | ||
1213 | var targetPath = binding["<-"] || binding["->"] || binding["<->>"] || binding["<<->"]; | ||
1214 | |||
1215 | if (targetPath[0] !== "@") { | ||
1216 | logger.error("Invalid binding syntax '" + targetPath + "', should be in the form of '@label.path'."); | ||
1217 | throw "Invalid binding syntax '" + targetPath + "'"; | ||
1218 | } | ||
1219 | if ("->" in binding || "<->>" in binding) { | ||
1220 | binding.boundObject = object; | ||
1221 | binding.boundObjectPropertyPath = sourcePath; | ||
1222 | |||
1223 | dotIndex = targetPath.indexOf("."); | ||
1224 | object = deserializer.getObjectByLabel(targetPath.slice(1, dotIndex)); | ||
1225 | sourcePath = targetPath.slice(dotIndex+1); | ||
1226 | } else { | ||
1227 | dotIndex = targetPath.indexOf("."); | ||
1228 | binding.boundObject = deserializer.getObjectByLabel(targetPath.slice(1, dotIndex)); | ||
1229 | binding.boundObjectPropertyPath = targetPath.slice(dotIndex+1); | ||
1230 | } | ||
1231 | |||
1232 | if ("<-" in binding || "->" in binding) { | ||
1233 | binding.oneway = true; | ||
1234 | } | ||
1235 | } | ||
1236 | Object.defineBinding(object, sourcePath, binding); | ||
1207 | } | 1237 | } |
1208 | }); | 1238 | }); |
1209 | 1239 | ||