Show More
@@ -31,12 +31,14 b' define([' | |||
|
31 | 31 | |
|
32 | 32 | // Load the initial state of the widget manager if a load callback was |
|
33 | 33 | // registered. |
|
34 | var that = this; | |
|
34 | 35 | if (WidgetManager._load_callback) { |
|
35 |
|
|
|
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 | 41 | // Setup state saving code. |
|
39 | var that = this; | |
|
40 | 42 | this.notebook.events.on('before_save.Notebook', function() { |
|
41 | 43 | var save_callback = WidgetManager._save_callback; |
|
42 | 44 | var options = WidgetManager._get_state_options; |
@@ -69,6 +71,17 b' define([' | |||
|
69 | 71 | |
|
70 | 72 | WidgetManager.set_state_callbacks = function (load_callback, save_callback, options) { |
|
71 | 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 | 85 | WidgetManager._load_callback = load_callback; |
|
73 | 86 | WidgetManager._save_callback = save_callback; |
|
74 | 87 | WidgetManager._get_state_options = options; |
@@ -76,7 +89,9 b' define([' | |||
|
76 | 89 | // Use the load callback to immediately load widget states. |
|
77 | 90 | WidgetManager._managers.forEach(function(manager) { |
|
78 | 91 | if (load_callback) { |
|
79 |
|
|
|
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