Manage application context
The application context is mainly (but not only) driven by the client router, which observes the url hash and converts it to a context. It can also be used as a global variable to store application states.
With KissJS, the url hash must contain the following parameter:
- ui: it stands for "user interface" and is used to display the main view
The url hash may contain other informations depending on your application. For example, at PickaForm, we use:
- applicationId: the active application id
- modelId: the active model id
- viewType: the active view type (datatable|calendar|kanban|gallery|...)
- viewId: the active view id
- recordId: the active record id (when displayed in a form)
- themeColor: the current application CSS theme color
- themeGeometry: the current application CSS theme geometry
- etc...
Members
# static changes
Last context changes
Example
console.log(kiss.context.changes)
// Output:
{ui: false, chapterId: false, sectionId: true}
# static history
Context history
Keep the history of visited routes
Example
console.log(kiss.context.history)
// Output:
[
{ui: "tutorial", chapterId: "1", sectionId: "2"},
{ui: "tutorial", chapterId: "1", sectionId: "7"},
{ui: "tutorial", chapterId: "2", sectionId: "3"}
// ...
]
# static lastContext
Last context
Example
console.log(kiss.context.lastContext)
// Output:
{ui: "tutorial", chapterId: "2", sectionId: "3"}
Methods
# static hasChanged(propertyNameopt) → {object}
Allow to check how the context has changed during the last routing event
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
propertyName |
string
|
<optional> |
The property to check. If not provided, it returns all the property changes. |
Where each property value is a boolean (true means "has changed")
object
Example
console.log(kiss.context.hasChanged())
// Output:
{
ui: false,
viewId: true,
themeColor: false
}
console.log(kiss.context.hasChanged("ui")) // Output: false
# static update(newContext)
Update the application context:
- you can use this as a global way to save some of your application states
- the whole context history is saved in kiss.context.history
Parameters:
Name | Type | Description |
---|---|---|
newContext |
object
|
Example
kiss.context.update({
applicationId: "c393b159-2dd2-41e0-9d68-17c40f7088ab",
viewId: "56b64b39-e932-49ae-86f2-30058345d9c8",
language: "fr"
})