new (require("nmodule/webEditors/rc/wb/mgr/MgrStateHandler"))()
- Description:
Constructor not to be called directly. Call
.make()instead.
- Source:
Methods
deserializeFromStorage() → {Object}
- Description:
Retrieve the state from storage and return the state object. This will be called
early in the manager's load process in order for it to be able to access relevant
state before the model is created. The object returned from this method will be
passed back to the restore function later in the load process.
- Source:
Returns:
- the stored state deserialized from JSON.
- Type
- Object
doRestore(mgr, obj) → {Promise}
- Description:
Use the deserialized object to restore the state of the manager.
This will restore the basic state, then invoke the custom functions on the
manager itself, if they are defined.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being restored. |
obj |
Object | the object containing the state to be restored |
Returns:
- Type
- Promise
doSave(mgr, state)
- Description:
Save the Manager's state to the given object, prior to serialization.
This will save the basic state supported for all Manager views, and then
try to see if the Manager provides its own functions for saving custom
data.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being saved. |
state |
Object | an object instance that will contain the state to be serialized. |
postRestore(mgr, obj) → {Promise}
- Description:
Test whether the Manager has a
postRestorefunction, and invoke it, if found.
This allows for additional actions such as clean up or other calls to be handled after
restoring the state.
- Source:
- Since:
- Niagara 4.12
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being restored. |
obj |
Object |
Returns:
- The Promise returned by the Manager's function
if the manager does not provide the function.
- Type
- Promise
restore(mgr, state) → {Promise}
- Description:
Restore the state of a
Manager. This function will retrieve the stored
state information from session storage using the Manager's key. It takes a
deserialized state object returned from an earlier call todeserializeFromStorage.
The properties of that object will then be used to restore the prior
state.The default
restoreimplementation will restore the visibility of the table
columns and the discovery tables. If the Manager providesrestoreStateForKeyand/or
restoreStateForOrdfunctions to correspond to the save functions, these will be
called with the deserialized versions of the objects the save functions returned.
- Source:
Example
Add a function on the Manager to restore the items found in the last discovery.
MyDeviceMgr.prototype.restoreStateForOrd = function (state) {
if (state.discoveries) {
this.discoveredItems = state.discoveries;
}
return this.reloadLearnModel(); // Returns a Promise that will reload the table
};
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being restored. |
state |
Object | a deserialized state object with properties containing the state to be restored. |
Returns:
- A promise resolved when the state restoration has completed.
- Type
- Promise
restoreForKey(mgr, obj) → {Promise}
- Description:
Test whether the Manager has a
restoreStateForKeyfunction, and invoke it, if found.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being restored. |
obj |
Object | the object containing the state to be restored |
Returns:
- The Promise returned by the Manager's function, or undefined
if the manager does not provide the function.
- Type
- Promise
restoreForOrd(mgr, obj) → {Promise}
- Description:
Test whether the Manager has a
restoreStateForOrdfunction, and invoke it, if found.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being restored. |
obj |
Object |
Returns:
- The Promise returned by the Manager's function, or undefined
if the manager does not provide the function.
- Type
- Promise
save(mgr) → {Promise}
- Description:
Save the state of the
Managerto session storage. This will perform three steps:
first the manager's state is saved as properties upon a state object, secondly the
object is serialized to JSON, and finally the JSON string is placed in session storage.The default save implementation will save the common basic state of the manager;
that is the visibility of the table columns and the visibility of the discovery table.
The manager can also provide functions to save state, which will be called by
this type, if defined. The manager may provide asaveStateForKeyand or asaveStateForOrd
function. ThesaveStateForOrdfunction will be used to store information against a particular
ord loaded in the manager, typically to save discovery data. Only the last ord that was loaded
for a particular manager type will have its ord data saved. Any previous ord data for the
same manager type will not be reloaded and thus will be erased when the data is saved again.
ThesaveStateForKeyfunction can be used to save generic data for the type of Manager.
Both of these functions should return an Object containing the state to save.
The returned value will be added to the data to be serialized. The Manager should also provide
corresponding restoreStateForKeyand/orrestoreStateForOrd` functions that will receive a
deserialized version of the object.
- Source:
Example
Add a function on the Manager to save the items found in the last discovery.
MyDeviceMgr.prototype.saveStateForOrd = function () {
return {
discoveries: this.discoveredItems // These objects will be serialized as JSON
};
};
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance requiring its state to be saved. |
Returns:
- Type
- Promise
saveForKey(mgr, state)
- Description:
Test whether the Manager has a
saveStateForKeyfunction, and invoke it, if found.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being saved. |
state |
Object | an object instance that will contain the state to be serialized. |
saveForOrd(mgr, state)
- Description:
Test whether the Manager has a
saveStateForOrdfunction, and invoke it, if found.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
mgr |
module:nmodule/webEditors/rc/wb/mgr/Manager | the Manager instance being saved. |
state |
Object | an object instance that will contain the state to be serialized. |
(static) make(params) → {Promise.<module:nmodule/webEditors/rc/wb/mgr/MgrStateHandler>}
- Description:
Takes a key string that will be used to index the
state information in the storage. This key is usually derived from
the Manager widget'smoduleNameandkeyNameparameters.Note that
MgrStateHandlerrelies uponSyncedSessionStoragewhich can
take up to 1000ms to initialize, so this may take that long to resolve.
- Source:
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
params |
string | Object | the parameters object or a string containing the Properties
|
Returns:
- Type
- Promise.<module:nmodule/webEditors/rc/wb/mgr/MgrStateHandler>