From 3a9d888f02caa321f878e998affa639f765167f4 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 20 Jun 2014 10:47:04 -0700 Subject: [PATCH] Removed respect_order and finally removed the children dict of the containerview --- IPython/html/static/widgets/js/widget.js | 68 +++++-------------- .../static/widgets/js/widget_container.js | 2 - 2 files changed, 16 insertions(+), 54 deletions(-) diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js index 70c4a0b8e..c85b84ccf 100644 --- a/IPython/html/static/widgets/js/widget.js +++ b/IPython/html/static/widgets/js/widget.js @@ -339,7 +339,7 @@ function(WidgetManager, _, Backbone){ return null; }, - do_diff: function(old_list, new_list, removed_callback, added_callback, respect_order) { + do_diff: function(old_list, new_list, removed_callback, added_callback) { // Difference a changed list and call remove and add callbacks for // each removed and added item in the new list. // @@ -351,60 +351,24 @@ function(WidgetManager, _, Backbone){ // Callback that is called for each item removed. // added_callback : Callback(item) // Callback that is called for each item added. - // [respect_order] : bool [True] - // Whether or not the order of the list matters. - if (respect_order || respect_order===undefined) { - // Walk the lists until an unequal entry is found. - var i; - for (i = 0; i < new_list.length; i++) { - if (i < old_list.length || new_list[i] !== old_list[i]) { - break; - } - } - - // Remove the non-matching items from the old list. - for (var j = i; j < old_list.length; j++) { - removed_callback(old_list[j]); - } - - // Add the rest of the new list items. - for (i; i < new_list.length; i++) { - added_callback(new_list[i]); - } - } else { - // removed items - _.each(this.difference(old_list, new_list), function(item, index, list) { - removed_callback(item); - }, this); - - // added items - _.each(this.difference(new_list, old_list), function(item, index, list) { - added_callback(item); - }, this); - } - }, - - difference: function(a, b) { - // Calculate the difference of two lists by contents. - // - // This function is like the underscore difference function - // except it will not fail when given a list with duplicates. - // i.e.: - // diff([1, 2, 2, 3], [3, 2]) - // Underscores results: - // [1] - // This method: - // [1, 2] - var contents = a.slice(0); - var found_index; - for (var i = 0; i < b.length; i++) { - found_index = _.indexOf(contents, b[i]); - if (found_index >= 0) { - contents.splice(found_index, 1); + // Walk the lists until an unequal entry is found. + var i; + for (i = 0; i < new_list.length; i++) { + if (i < old_list.length || new_list[i] !== old_list[i]) { + break; } } - return contents; + + // Remove the non-matching items from the old list. + for (var j = i; j < old_list.length; j++) { + removed_callback(old_list[j]); + } + + // Add the rest of the new list items. + for (i; i < new_list.length; i++) { + added_callback(new_list[i]); + } }, callbacks: function(){ diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index cc05f7225..95e519d35 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -21,7 +21,6 @@ define(["widgets/js/widget"], function(WidgetManager) { // Called when view is rendered. this.$el.addClass('widget-container') .addClass('vbox'); - this.children={}; this.update_children([], this.model.get('children')); this.model.on('change:children', function(model, value, options) { this.update_children(model.previous('children'), value); @@ -80,7 +79,6 @@ define(["widgets/js/widget"], function(WidgetManager) { render: function(){ // Called when view is rendered. var that = this; - this.children={}; this.$el.on("remove", function(){ that.$backdrop.remove();