.new StateModule(paramsopt)
StateModule is useful for apps, where you need state manipulation.
This can be: transitions between screens, games, development moments.
You can check basic/state example.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
params |
Object
|
<optional> |
Example
Creating a state module
new App([
// ...
new StateModule().default({
sphereColor: 0xff0000
})
]);
Methods
(static) .config(configs)
Load configurations from object.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
configs |
Object
|
Configuration data |
Example
Adding `green` configuration
state.config({
green: {
sphereColor: 0x00ff00,
planeColor: 0x00ff00
}
});
(static) .current(config, trueVal, falseVal)
Return trueVal if config match current configuration, in other case - return falseVal.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
config |
String
|
Configuration name. |
trueVal |
Any
|
Value returned if condition is truthy. |
falseVal |
Any
|
Value returned if condition is falsy. |
(static) .default(data)
Add default configuration.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object
|
Configuration setup |
Example
new WHS.StateModule().default({
sphereColor: UTILS.$colors.mesh,
planeColor: 0x447F8B
})
(static) .get(key)
Return data of parameter.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
String
|
Parameter name. |
Example
state.get('sphereColor'); // 0x00ff00
(static) .prev(config, trueVal, falseVal)
Return trueVal if config match previous configuration, in other case - return falseVal.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
config |
String
|
Configuration name. |
trueVal |
Any
|
Value returned if condition is truthy. |
falseVal |
Any
|
Value returned if condition is falsy. |
(static) .set(data)
Set current parameters.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object
|
Configuration parameters. |
Example
state.set({
sphereColor: 0x00ff00
});
(static) .setEqualCheck(func)
Sets an equalCheck function
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
func |
function
|
function to generate equal check |
(static) .to(configName)
Switch to configuration.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
configName |
String
|
Configuration name. |
Example
Changes configuration to `green`
state.to('green');
(static) .update(updates)
Load updates from object.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
updates |
Object
|
Updates data |
Example
Update callback for `sphereColor`
state.update({
sphereColor: color => sphere.material.color.setHex(color)
});