The state store can keep track of any JSON-style data object for other modules to access and use.
The state store is used as centralized data storage for all modules, especially when concerning data that is shared among 2 or more modules. When individual modules need to update specific data, modifications through the state store ensure that other modules that need to be aware of the latest available data can do so without specific input from the module changing it.
The state store can store any number of states, as defined by a data string. See module:event-store#event:ModifyState. It is able to associate any data object with that particular state, although it is optimized to store key-value Objects.
(require("state-store"))(viewer)
Creates and initializes the state store.
Parameters:
Name | Type | Description |
---|---|---|
viewer |
Core |
The core viewer to which the module will attach. |
Fires:
Listens to Events:
Example
var StateStore = require('state-store.js');
// a generic Viewer constructor
function Viewer(opts) {
// other modules will expect this to be present
this.stateStore = StateStore(this);
}
Members
(inner) FieldList
The known set of fields and metadata on the form.
Properties:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
templateDocumentId |
string |
The unique id used to determine which document belongs to the form. The form cannot be loaded if this value is not defined. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
formName |
string | <optional> |
"" |
The display name of the form. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
formDefinitionId |
string | <optional> |
The unique id to use to save the form to the server. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
formRoles |
Object | <optional> |
A hash object used to store and access the metadata for each role in the form. The key for this hash object is the Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
groups |
Object | <optional> |
A hash object used to store and access the metadata for each group in the form. The key for this hash object is the Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fieldList |
Object |
A hash object used to store and access the metadata for each field in the form. The key for this hash object is the Properties
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
globalSettings |
Object |
Settings that apply globally to the template. Properties
|
Example
var fieldList = viewer.stateStore.getState('FieldList');
(inner) FormDefinition
Defines the schema of the template form that is saved to the server, including all of the metadata required to load and recreate the form.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
templateDocumentId |
string |
The unique id used to determine which document belongs to the form. The form cannot be loaded if this value is not defined. |
||
formName |
string | <optional> |
"" |
The display name of the form. |
formDefinitionId |
string | <optional> |
The unique id to use to save the form to the server. |
|
formRoles |
Array | <optional> |
The data here is similar to the |
|
groups |
Array | <optional> |
The data here is similar to the |
|
formData |
Array |
The data here is similar to the |
||
globalSettings |
Object |
An instance of the module:state-store~GlobalSettings object used for this form. |
(inner) PageData
Defines the set of currently known pages -- ones that have loaded at least once in the viewer -- and their sizes. It is a hash object, using the page number as the object key, and the following properties as the object value.
Properties:
Name | Type | Description |
---|---|---|
width |
number |
The width of the page. |
height |
number |
The height of the page. |
Methods
destroy()
Destroys the instance of the State Store.
getState(key) → {*|undefined}
Gets the current state.
Parameters:
Name | Type | Description |
---|---|---|
key |
string |
The name of the state value being retrieved. |
Returns:
The state value associated with the specified key or undefined
if the state value does not exist.
- Type
- * | undefined