Skip to content

Commit dd3adfe

Browse files
committed
MAINT: Move function creation out of loop.
See https://jslinterrors.com/dont-make-functions-within-a-loop for why this is a really bad thing to do.
1 parent 9c12ea4 commit dd3adfe

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

jupyter_notebook/static/tree/js/notebooklist.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ define([
157157
{
158158
files = event.originalEvent.target.files;
159159
}
160+
161+
var reader_onload = function (event) {
162+
var item = $(event.target).data('item');
163+
that.add_file_data(event.target.result, item);
164+
that.add_upload_button(item);
165+
};
166+
var reader_onerror = function (event) {
167+
var item = $(event.target).data('item');
168+
var name = item.data('name');
169+
item.remove();
170+
dialog.modal({
171+
title : 'Failed to read file',
172+
body : "Failed to read file '" + name + "'",
173+
buttons : {'OK' : { 'class' : 'btn-primary' }}
174+
});
175+
};
176+
160177
for (var i = 0; i < files.length; i++) {
161178
var f = files[i];
162179
var name_and_ext = utils.splitext(f.name);
@@ -175,21 +192,8 @@ define([
175192
// Store the list item in the reader so we can use it later
176193
// to know which item it belongs to.
177194
$(reader).data('item', item);
178-
reader.onload = function (event) {
179-
var item = $(event.target).data('item');
180-
that.add_file_data(event.target.result, item);
181-
that.add_upload_button(item);
182-
};
183-
reader.onerror = function (event) {
184-
var item = $(event.target).data('item');
185-
var name = item.data('name');
186-
item.remove();
187-
dialog.modal({
188-
title : 'Failed to read file',
189-
body : "Failed to read file '" + name + "'",
190-
buttons : {'OK' : { 'class' : 'btn-primary' }}
191-
});
192-
};
195+
reader.onload = reader_onload;
196+
reader.onerror = reader_onerror;
193197
}
194198
// Replace the file input form wth a clone of itself. This is required to
195199
// reset the form. Otherwise, if you upload a file, delete it and try to

0 commit comments

Comments
 (0)