litespeed.js
Version:
Lite & fast micro javascript framework that is easy to learn
111 lines (73 loc) • 2.35 kB
Markdown
The state service manages the application state registration and routing logic.
- [add(path, view)](
- [change(url, replace)](
- [reload()](
- [match(location)](
- [getCurrent()](
- [getPrevious()](
- [params](params)
Add a new state to the app states list. When a the app init or when a URL changes the [match](
Param | Type | Description
--- | --- | ---
**path** | string | State URL path
**view** | object | State [view object]((/docs/services/view.md))
Returns state object instance.
```js
state.add('/contact-us', {
'template': '/templates/contact-us.html',
'repeat': false,
});
```
Change app current state. Use the replace param to control whether the new state should replace current state in History API or added as a new state. This mainly affects the behaviour of the browser back button.
Param | Type | Description
--- | --- | ---
**url** | string | New state URL
**replace** | boolean | Add new state or replace current one
Returns state object instance.
```js
state.change('/new-view', false);
```
The reload method reload current app state and re-render the [ls-scope](/docs/views/scope.md) view component
Returns state object instance.
```js
state.reload();
```
The match method iterate over all the states that has been registered to the state service with the [add](
Param | Type | Description
--- | --- | ---
**location** | object | [location object](https://www.w3schools.com/jsref/obj_location.asp)
Returns matching state or null if no state was found.
```js
state.change('/new-view', false);
```
Get current app state object.
Returns current app state object.
```js
state.getCurrent();
```
Get previous app state object.
Returns previous app state object.
```js
state.getPrevious();
```