https://github.com/webix-hub/jet-restate
  
  
    Reactive state for Webix Jet apps 
    https://github.com/webix-hub/jet-restate
  
        Last synced: 4 months ago 
        JSON representation
    
Reactive state for Webix Jet apps
- Host: GitHub
- URL: https://github.com/webix-hub/jet-restate
- Owner: webix-hub
- Created: 2020-02-06T10:46:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T10:41:41.000Z (over 3 years ago)
- Last Synced: 2025-03-11T20:52:22.737Z (8 months ago)
- Language: JavaScript
- Homepage: https://webix.com/webixjet/
- Size: 111 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 5
- 
            Metadata Files:
            - Readme: README.md
 
Awesome Lists containing this project
README
          Reactive state for Webix Jet apps
====
## Why it is necessary
Webix Jet provides two ways to cross-view communication
- events
- view parameters, 
Reactive state provides a combination of both, with ability to maintain state ( as parameters ) and ability without predefined source/target ( as events ) 
## How to use
```js
import { createState, link } from "jet-restate";
...
const state = createState({
    mode: config.mode || "grid",
    selectedItem: [],
    search: "",
    path: config.path || "/",
    clipboard: null,
});
this.show("child", { target:"left", params: { state }})
this.show("child", { target:"right", params: { state }})
```
now in any of child views
```js
    const state = this.getParam("state");
    //change state
    state.mode = newValue;
    //react on state changes
    this.on(state.$changes, "mode", value => {
        this.getRoot().setValue(value);
    });
```
#### Extending state
It possible to add new vars to the state.
There is no way to remove them though.
```js
const state = createState({ mode:"grid" });
state.$extend({ path:"/" })
```