@aslab/relax
v0.0.11
Published
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Greenkeeper badge](https://badges.greenkeeper.io/alexjoverm/typescript-library-starter.svg)](https://greenkeeper.io/) [![Travi
Downloads
33
Readme
Relax from ASLab
Features
- simple state management without bullshit
- sharing store between components
- support mutiple stores
- update UI in response to any store changes
Usage
see https://codesandbox.io/s/7mrqxzkwl6
yarn add @aslab/relax
Sample code
- create a store file (say store.ts)
import { link } from "@aslab/relax"
const store = {
/** this is the name */
name: "Alex",
score: 100,
nationality: "Martian"
}
const { use, commit } = link(store)
export { store, use, commit }
- use it in your components
import * as React from "react";
import { render } from "react-dom";
import { store, use, commit } from "./store";
import "./styles.css";
function Btn1() {
return (
<button
onClick={() => {
store.score++;
}}
>
increase score
</button>
);
}
function Btn2() {
return (
<button
onClick={() => {
setTimeout(() => {
store.score++;
}, 1000);
}}
>
async change
</button>
);
}
function App() {
const { name, score } = use(() => {
return {
name: store.name,
score: store.score
};
});
return (
<div className="App">
<div>Name: {name}</div>
<div>Score: {score}</div>
<Btn1 />
<Btn2 />
</div>
);
return <h1>a</h1>;
}
const rootElement = document.getElementById("root");
render(<App />, rootElement);
3 Relax and see it working!