##// END OF EJS Templates
Document set_state_callbacks and,...
Jonathan Frederic -
Show More
@@ -31,12 +31,14 b' define(['
31
31
32 // Load the initial state of the widget manager if a load callback was
32 // Load the initial state of the widget manager if a load callback was
33 // registered.
33 // registered.
34 var that = this;
34 if (WidgetManager._load_callback) {
35 if (WidgetManager._load_callback) {
35 this.set_state(WidgetManager._load_callback.call(this));
36 Promise.resolve(WidgetManager._load_callback.call(this)).then(function(state) {
37 that.set_state(state);
38 }).catch(utils.reject('Error loading widget manager state', true));
36 }
39 }
37
40
38 // Setup state saving code.
41 // Setup state saving code.
39 var that = this;
40 this.notebook.events.on('before_save.Notebook', function() {
42 this.notebook.events.on('before_save.Notebook', function() {
41 var save_callback = WidgetManager._save_callback;
43 var save_callback = WidgetManager._save_callback;
42 var options = WidgetManager._get_state_options;
44 var options = WidgetManager._get_state_options;
@@ -69,6 +71,17 b' define(['
69
71
70 WidgetManager.set_state_callbacks = function (load_callback, save_callback, options) {
72 WidgetManager.set_state_callbacks = function (load_callback, save_callback, options) {
71 // Registers callbacks for widget state persistence.
73 // Registers callbacks for widget state persistence.
74 //
75 // Parameters
76 // ----------
77 // load_callback: function()
78 // function that is called when the widget manager state should be
79 // loaded. This function should return a promise for the widget
80 // manager state. An empty state is an empty dictionary `{}`.
81 // save_callback: function(state as dictionary)
82 // function that is called when the notebook is saved or autosaved.
83 // The current state of the widget manager is passed in as the first
84 // argument.
72 WidgetManager._load_callback = load_callback;
85 WidgetManager._load_callback = load_callback;
73 WidgetManager._save_callback = save_callback;
86 WidgetManager._save_callback = save_callback;
74 WidgetManager._get_state_options = options;
87 WidgetManager._get_state_options = options;
@@ -76,7 +89,9 b' define(['
76 // Use the load callback to immediately load widget states.
89 // Use the load callback to immediately load widget states.
77 WidgetManager._managers.forEach(function(manager) {
90 WidgetManager._managers.forEach(function(manager) {
78 if (load_callback) {
91 if (load_callback) {
79 manager.set_state(load_callback.call(manager));
92 Promise.resolve(load_callback.call(manager)).then(function(state) {
93 manager.set_state(state);
94 }).catch(utils.reject('Error loading widget manager state', true));
80 }
95 }
81 });
96 });
82 };
97 };
General Comments 0
You need to be logged in to leave comments. Login now