Save and Load State
Continuing with this simple example, we add another useful capability - saving the state of the controller to the project, and loading it back when the project file is opened.
You may want to save the state of your controller directly in the project so the next time the user opens the project, any state information is reloaded.
To do this:
Keep all information that needs to be saved and loaded in one JavaScript object.
Whenever something changes in these settings, save it out using the
saveSettings
command.On startup, retrieve the input settings using the
loadSettings
command.
In this example, the JavaScript object that manages all of the state information is called “settings.” Saving the state the code looks like this:
// Save this latest state in the project.
scheduler.saveSettings(inputName, JSON.stringify(settings));
This should be called any time the settings change, typically when the user makes a change in the UI.
To retrieve the settings, call loadSettings
from the project when the ServiceHandler
connects:
// On startup, retrieve the input settings from the project.
scheduler.loadSettings(inputName, (projectSettings) => {
// Convert into a Javascript object.
let newSettings = JSON.parse(projectSettings);
// ... apply the settings to the UI
});
Last updated