ipython/ipython — pull request #6632 by SylvainCorlay (2014-10-06 18:18:48+00:00)
Title: Allow widget models and views to be loaded from require modules

@jasongrout @jdfreder @takluyver @ellisonbg
This PR enables the loading of widget views and widget models from the backend. It differs from PR #6494 in that it
-allows for both models and views to be loaded from the backend.
-the loading of the view modules happens at import time rather than display time.
-the JavaScript-specific requirejs path is not part of the widget class, but only present in the `load_***_module function`, which contains the abstraction leaking.

How to use it: create two files in `/static/some/path` (or in nbextensions, it is not the point here)

* In some/path/TextView.js
```JavaScript
define(["widgets/js/widget"], function(widget) {
var TextView = widget.DOMWidgetView.extend({
render: function(){
this.$el.text("Hello World!");
},
});
return { "MyTextView": TextView };
});
```

* In some/path/TextModel.js
```JavaScript
define(["widgets/js/widget"], function(widget) {
var TextModel = widget.WidgetModel.extend({ });
return { "MyTextModel": TextModel };
});
```

* In your Python module
```Python
class MyText(DOMWidget):
_view_name = Unicode('MyTextView', sync=True)
_model_name = Unicode('MyTextModel', sync=True)

load_view_module('MyTextView', 'some/path/TextView')
load_model_module('MyTextModel', 'some/path/TextModel')
```

* The client code for the same widget in Thomas's PR #6494 would be
```Python
class MyText(DOMWidget):
_view_name = Unicode('MyTextView', sync=True)
_model_name = Unicode('MyTextModel', sync=True)
_view_module = Unicode('some/path/TextView', sync=True)
```
but the loading of the view module would happen at display time rather than import time. Besides, the abstraction leaking (the JavaScript requirejs path) goes all the way to the widget class itself instead of being contained in the loading function. Besides, PR #6494 introduces a difference in how you overload models and views.

Besides, we should probably not introduce the change in the loading of views and later in the loading of the models. We should probably modify both at the same time so that people can change their code in one time.