0.4.5 • Published 2 years ago
property-process v0.4.5
PropertyProcess
watch and handle properties easily
Install
npm install --save property-process
yarn add property-process
Usage
import React from "react";
import { registViewModel, useViewModel } from "property-process";
type CountType = {
count: number;
multiply: number;
nested: {
test: string[];
deepTest: {
level: number;
};
};
increase: (payload: { amount: number }) => void;
decrease: (payload: { amount: number }) => void;
};
const appViewModel = registViewModel<CountType>(
{
count: 0,
multiply: 0,
nested: {
test: [],
deepTest: {
level: 1,
},
},
increase(payload) {
this.count = this.count + 1 + payload.amount;
},
decrease() {
this.count = this.count - 1;
},
},
{ deep: true }
);
function App() {
const [state, send] = useViewModel(appViewModel, ["count", "nested.test"]);
return (
<div
style={{
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
}}
>
<div style={{ display: "flex", gap: "4px" }}>
<button onClick={() => send("increase", { amount: 1 })}>+</button>
<span>{state.count}</span>
<button onClick={() => send("decrease", { amount: 1 })}>-</button>
</div>
<button onClick={() => state.nested.test.push("1")}>Nested Test</button>
</div>
);
}
export default App;
Furture Feature
- Add PropertyHandler Options
0.1.10
3 years ago
0.1.11
2 years ago
0.1.12
2 years ago
0.1.13
2 years ago
0.1.14
2 years ago
0.1.15
2 years ago
0.3.0
2 years ago
0.3.6
2 years ago
0.1.8
3 years ago
0.3.5
2 years ago
0.3.8
2 years ago
0.3.7
2 years ago
0.1.9
3 years ago
0.3.2
2 years ago
0.3.1
2 years ago
0.3.4
2 years ago
0.3.3
2 years ago
0.3.9
2 years ago
0.3.13
2 years ago
0.3.12
2 years ago
0.3.11
2 years ago
0.3.10
2 years ago
0.2.1
2 years ago
0.2.0
2 years ago
0.4.5
2 years ago
0.2.7
2 years ago
0.1.16
2 years ago
0.4.4
2 years ago
0.2.6
2 years ago
0.1.17
2 years ago
0.1.18
2 years ago
0.2.8
2 years ago
0.1.19
2 years ago
0.4.1
2 years ago
0.2.3
2 years ago
0.2.2
2 years ago
0.4.3
2 years ago
0.2.5
2 years ago
0.4.2
2 years ago
0.2.4
2 years ago
0.1.7
3 years ago
0.1.6
3 years ago
0.1.5
3 years ago
0.1.4
3 years ago
0.1.3
3 years ago
0.1.2
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago