lib/assets/javascripts/transistor-backbone.js in transistor-0.1.4 vs lib/assets/javascripts/transistor-backbone.js in transistor-0.1.5
- old
+ new
@@ -4,13 +4,18 @@
window.Transistor = {};
}
(function (transistor) {
var BackboneCollection = (function () {
- return function (radio, channel) {
- var H, backbone_collection, collection_interface, binder;
+ return function (options) {
+ var channel, radio, control, H, backbone_collection, collection_interface, control_interface, binder;
+ channel = options.channel;
+ radio = options.radio;
+ control = options.control;
+
+
H = (function () {
return {
};
}());
@@ -21,35 +26,38 @@
remove: backbone_collection.remove,
reset: backbone_collection.reset,
set: backbone_collection.set
};
+ control_interface = {
+ add: function (entry) { control.insert(channel, entry); },
+ remove: function (model) { control.remove(channel, model.id); },
+ set: function (collection) { control.set(channel, collection); }
+ };
+ control_interface.reset = control_interface.set;
+
(function (writer) {
- var frozen = true,
+ var privatized = true,
delegate = function (func) {
writer[func] = (function (name) {
return function () {
- if (frozen) {
- throw "BackboneCollection is not mutable by user.";
+ if (privatized) {
+ if (!control) {
+ throw "BackboneCollection is not mutable by user.";
+ } else {
+ control_interface[name].apply(control_interface, arguments);
+ }
} else {
return collection_interface[name].apply(backbone_collection, arguments);
}
};
}(func));
};
- collection_interface.unfreeze = function () {
- frozen = false;
- };
-
- collection_interface.freeze = function () {
- frozen = true;
- };
-
collection_interface.unfrozen = function (unfrozen_context) {
- collection_interface.unfreeze();
+ privatized = false;
unfrozen_context();
- collection_interface.freeze();
+ privatized = true;
};
delegate('add');
delegate('remove');
delegate('reset');