##// END OF EJS Templates
use es6
Jonathan Frederic -
Show More
@@ -5,8 +5,7 b' define(['
5 'base/js/namespace',
5 'base/js/namespace',
6 'jquery',
6 'jquery',
7 'codemirror/lib/codemirror',
7 'codemirror/lib/codemirror',
8 'rsvp',
8 ], function(IPython, $, CodeMirror){
9 ], function(IPython, $, CodeMirror, rsvp){
10 "use strict";
9 "use strict";
11
10
12 IPython.load_extensions = function () {
11 IPython.load_extensions = function () {
@@ -641,7 +640,7 b' define(['
641 // Tries to load a class from a module using require.js, if a module
640 // Tries to load a class from a module using require.js, if a module
642 // is specified, otherwise tries to load a class from the global
641 // is specified, otherwise tries to load a class from the global
643 // registry, if the global registry is provided.
642 // registry, if the global registry is provided.
644 return new rsvp.Promise(function(resolve, reject) {
643 return new Promise(function(resolve, reject) {
645
644
646 // Try loading the view module using require.js
645 // Try loading the view module using require.js
647 if (module_name) {
646 if (module_name) {
@@ -664,13 +663,13 b' define(['
664
663
665 var resolve_dict = function(d) {
664 var resolve_dict = function(d) {
666 // Resolve a promiseful dictionary.
665 // Resolve a promiseful dictionary.
667 // Returns a single rsvp.Promise.
666 // Returns a single Promise.
668 var keys = Object.keys(d);
667 var keys = Object.keys(d);
669 var values = [];
668 var values = [];
670 keys.forEach(function(key) {
669 keys.forEach(function(key) {
671 values.push(d[key]);
670 values.push(d[key]);
672 });
671 });
673 return rsvp.Promise.all(values).then(function(v) {
672 return Promise.all(values).then(function(v) {
674 d = {};
673 d = {};
675 for(var i=0; i<keys.length; i++) {
674 for(var i=0; i<keys.length; i++) {
676 d[keys[i]] = v[i];
675 d[keys[i]] = v[i];
@@ -707,15 +706,15 b' define(['
707 WrappedError.prototype = Object.create(Error.prototype, {});
706 WrappedError.prototype = Object.create(Error.prototype, {});
708
707
709 var reject = function(message, log) {
708 var reject = function(message, log) {
710 // Creates a wrappable rsvp.Promise rejection function.
709 // Creates a wrappable Promise rejection function.
711 //
710 //
712 // Creates a function that returns a rsvp.Promise.reject with a new WrappedError
711 // Creates a function that returns a Promise.reject with a new WrappedError
713 // that has the provided message and wraps the original error that
712 // that has the provided message and wraps the original error that
714 // caused the promise to reject.
713 // caused the promise to reject.
715 return function(error) {
714 return function(error) {
716 var wrapped_error = new WrappedError(message, error);
715 var wrapped_error = new WrappedError(message, error);
717 if (log) console.error(wrapped_error);
716 if (log) console.error(wrapped_error);
718 return rsvp.Promise.reject(wrapped_error);
717 return Promise.reject(wrapped_error);
719 };
718 };
720 };
719 };
721
720
@@ -49,6 +49,7 b' require(['
49 custom
49 custom
50 ) {
50 ) {
51 "use strict";
51 "use strict";
52 console.log(promise);
52
53
53 // compat with old IPython, remove for IPython > 3.0
54 // compat with old IPython, remove for IPython > 3.0
54 window.CodeMirror = CodeMirror;
55 window.CodeMirror = CodeMirror;
@@ -5,8 +5,7 b' define(['
5 'base/js/namespace',
5 'base/js/namespace',
6 'jquery',
6 'jquery',
7 'base/js/utils',
7 'base/js/utils',
8 'rsvp',
8 ], function(IPython, $, utils) {
9 ], function(IPython, $, utils, rsvp) {
10 "use strict";
9 "use strict";
11
10
12 //-----------------------------------------------------------------------
11 //-----------------------------------------------------------------------
@@ -80,7 +79,7 b' define(['
80 that.unregister_comm(comm);
79 that.unregister_comm(comm);
81 var wrapped_error = new utils.WrappedError("Exception opening new comm", e);
80 var wrapped_error = new utils.WrappedError("Exception opening new comm", e);
82 console.error(wrapped_error);
81 console.error(wrapped_error);
83 return rsvp.Promise.reject(wrapped_error);
82 return Promise.reject(wrapped_error);
84 }
83 }
85 return comm;
84 return comm;
86 }, utils.reject('Could not open comm', true));
85 }, utils.reject('Could not open comm', true));
@@ -7,8 +7,7 b' define(['
7 "jquery",
7 "jquery",
8 "base/js/utils",
8 "base/js/utils",
9 "base/js/namespace",
9 "base/js/namespace",
10 'rsvp',
10 ], function (_, Backbone, $, utils, IPython) {
11 ], function (_, Backbone, $, utils, IPython, rsvp) {
12 "use strict";
11 "use strict";
13 //--------------------------------------------------------------------
12 //--------------------------------------------------------------------
14 // WidgetManager class
13 // WidgetManager class
@@ -50,7 +49,7 b' define(['
50 WidgetManager.prototype.display_view = function(msg, model) {
49 WidgetManager.prototype.display_view = function(msg, model) {
51 // Displays a view for a particular model.
50 // Displays a view for a particular model.
52 var that = this;
51 var that = this;
53 return new rsvp.Promise(function(resolve, reject) {
52 return new Promise(function(resolve, reject) {
54 var cell = that.get_msg_cell(msg.parent_header.msg_id);
53 var cell = that.get_msg_cell(msg.parent_header.msg_id);
55 if (cell === null) {
54 if (cell === null) {
56 reject(new Error("Could not determine where the display" +
55 reject(new Error("Could not determine where the display" +
@@ -241,7 +240,7 b' define(['
241 }, function(error) {
240 }, function(error) {
242 delete that._models[model_id];
241 delete that._models[model_id];
243 var wrapped_error = new utils.WrappedError("Couldn't create model", error);
242 var wrapped_error = new utils.WrappedError("Couldn't create model", error);
244 return rsvp.Promise.reject(wrapped_error);
243 return Promise.reject(wrapped_error);
245 });
244 });
246 this._models[model_id] = model_promise;
245 this._models[model_id] = model_promise;
247 return model_promise;
246 return model_promise;
@@ -7,8 +7,7 b' define(["widgets/js/manager",'
7 "jquery",
7 "jquery",
8 "base/js/utils",
8 "base/js/utils",
9 "base/js/namespace",
9 "base/js/namespace",
10 "rsvp",
10 ], function(widgetmanager, _, Backbone, $, utils, IPython){
11 ], function(widgetmanager, _, Backbone, $, utils, IPython, rsvp){
12
11
13 var WidgetModel = Backbone.Model.extend({
12 var WidgetModel = Backbone.Model.extend({
14 constructor: function (widget_manager, model_id, comm) {
13 constructor: function (widget_manager, model_id, comm) {
@@ -23,7 +22,7 b' define(["widgets/js/manager",'
23 // An ID unique to this model.
22 // An ID unique to this model.
24 // comm : Comm instance (optional)
23 // comm : Comm instance (optional)
25 this.widget_manager = widget_manager;
24 this.widget_manager = widget_manager;
26 this.state_change = rsvp.Promise.resolve();
25 this.state_change = Promise.resolve();
27 this._buffered_state_diff = {};
26 this._buffered_state_diff = {};
28 this.pending_msgs = 0;
27 this.pending_msgs = 0;
29 this.msg_buffer = null;
28 this.msg_buffer = null;
@@ -101,7 +100,7 b' define(["widgets/js/manager",'
101 } finally {
100 } finally {
102 that.state_lock = null;
101 that.state_lock = null;
103 }
102 }
104 return rsvp.Promise.resolve();
103 return Promise.resolve();
105 }, utils.reject("Couldn't set model state", true));
104 }, utils.reject("Couldn't set model state", true));
106 },
105 },
107
106
@@ -262,7 +261,7 b' define(["widgets/js/manager",'
262 _.each(value, function(sub_value, key) {
261 _.each(value, function(sub_value, key) {
263 unpacked.push(that._unpack_models(sub_value));
262 unpacked.push(that._unpack_models(sub_value));
264 });
263 });
265 return rsvp.Promise.all(unpacked);
264 return Promise.all(unpacked);
266 } else if (value instanceof Object) {
265 } else if (value instanceof Object) {
267 unpacked = {};
266 unpacked = {};
268 _.each(value, function(sub_value, key) {
267 _.each(value, function(sub_value, key) {
@@ -273,7 +272,7 b' define(["widgets/js/manager",'
273 // get_model returns a promise already
272 // get_model returns a promise already
274 return this.widget_manager.get_model(value.slice(10, value.length));
273 return this.widget_manager.get_model(value.slice(10, value.length));
275 } else {
274 } else {
276 return rsvp.Promise.resolve(value);
275 return Promise.resolve(value);
277 }
276 }
278 },
277 },
279
278
@@ -31,7 +31,6 b''
31 codemirror: 'components/codemirror',
31 codemirror: 'components/codemirror',
32 termjs: "components/term.js/src/term",
32 termjs: "components/term.js/src/term",
33 contents: '{{ contents_js_source }}',
33 contents: '{{ contents_js_source }}',
34 rsvp: "components/rsvp/rsvp",
35 },
34 },
36 shim: {
35 shim: {
37 underscore: {
36 underscore: {
General Comments 0
You need to be logged in to leave comments. Login now