Session
A session is used to store the data shared between actions.
@Mebo.register('myAction')
class MyAction extends Mebo.Action{
// ...
async _perform(data){
// sharing a value across the session
this.session().set('mySharedValue', 100);
// ...
}
}
This object is created automatically by Handler.create and Action.create.
Constructor Summary
Public Constructor | ||
public |
constructor(wrapup: Tasks) Creates a session |
Method Summary
Public Methods | ||
public |
Returns a value under the autofill data. |
|
public |
autofillKeys(): Array<string> Returns the keys included in the autofill data |
|
public |
Returns a cloned version of the current session where all autofill and arbitrary data are transferred to the cloned version. |
|
public |
Terminates the session by executing the wrapup tasks. |
|
public |
Returns an value assigned for the key inside of the arbitrary data |
|
public |
Returns a boolean telling if the input key is under the arbitrary data |
|
public |
hasAutofill(key: string): boolean Returns a boolean telling if the key exists under the autofill data. |
|
public |
Returns the keys included in the arbitrary data |
|
public |
Sets a key & value under the arbitrary data. |
|
public |
setAutofill(key: string, value: *) Sets a key & value under the autofill data |
|
public |
Returns the tasks object used to hold actions and promises that are triggered when finalizing (finalize) the session. |
Public Constructors
Public Methods
public autofill(key: string, defaultValue: *): * source
Returns a value under the autofill data.
This feature is used to set the initial input value for inputs that contain the autofill
property. It works by looking if the value of the autofill input's property is under the
Session.autofill then if found it sets the input value with the value of the
Session.autofill. This process occurs when a session is assigned to the action
(Action.setSession).
When inputs that contain the property autofill
are initialized through the
Handler they will try to find their values under the autofill,
however if a value is not defined for them they will assign their input value
to the autofill data automatically.
Params:
Name | Type | Attribute | Description |
key | string | key name used to query the autofill value |
|
defaultValue | * |
|
optional default value returned in case the key does not exist |
Return:
* |
public clone(): Session source
Returns a cloned version of the current session where all autofill and arbitrary data are transferred to the cloned version.
This feature is used by the actions during the session assignment (Action.setSession) to prevent that modifications done in the session of nested actions reflect back in the session used by the parent actions. Therefore, acting as scope for changes in the autofill & arbitrary data.
The current wrapup is also assigned to the cloned version.
public async finalize(): Promise source
Terminates the session by executing the wrapup tasks.
This is called by the Handler during the execution of Handler.output.
public get(key: string, defaultValue: *): * source
Returns an value assigned for the key inside of the arbitrary data
Params:
Name | Type | Attribute | Description |
key | string | name of the key |
|
defaultValue | * |
|
optional value returned when the key is not assigned |
Return:
* |
public has(key: string): boolean source
Returns a boolean telling if the input key is under the arbitrary data
Params:
Name | Type | Attribute | Description |
key | string | key name |
public hasAutofill(key: string): boolean source
Returns a boolean telling if the key exists under the autofill data.
Params:
Name | Type | Attribute | Description |
key | string | key name |
public set(key: string, value: *) source
Sets a key & value under the arbitrary data. This is used to store data that may be only available in specific handlers, for instance the request object created by express is assigned to the session through this method by the web handler.
Params:
Name | Type | Attribute | Description |
key | string | name of the key |
|
value | * | value for the key |
public setAutofill(key: string, value: *) source
Sets a key & value under the autofill data
Params:
Name | Type | Attribute | Description |
key | string | key name |
|
value | * | value associated with the key |
See:
public wrapup(): Tasks source
Returns the tasks object used to hold actions and promises that are triggered when finalizing (finalize) the session. Wrapup actions can be used to avoid the execution of an action that may be triggered multiple times across nested actions where ideally it should be executed only once in the end, after all nested actions are done.