hermes-io 2.9.74 → 2.9.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,24 +1,47 @@
1
1
  # hermes-io
2
2
  A lightweight React library that allows communication between components by using the observer pattern and the hook api.
3
3
 
4
+ ## Documentation
5
+ See: https://hermes-io-docs.vercel.app/
6
+
4
7
  ## Usage
5
8
  ```javascript
6
- function App({ notify }) {
7
- const increment = () => {
8
- notify({
9
- value: {
10
- type: INCREMENT,
11
- },
12
- });
13
- };
9
+ import { MicroStore } from "hermes-io";
10
+
11
+ export const store = new MicroStore();
12
+ export const storeId = 'counter-id';
13
+ ```
14
14
 
15
- const decrement = () => {
16
- notify({
17
- value: {
18
- type: DECREMENT,
19
- },
20
- });
15
+ ```javascript
16
+ export const actions = {
17
+ INCREMENT: "INCREMENT",
18
+ DECREMENT: "DECREMENT"
19
+ };
20
+
21
+ export default function reducer(store, action) {
22
+ const actionsMap = {
23
+ [actions.INCREMENT]: () => {
24
+ store.state.count += 1;
25
+ },
26
+ [actions.DECREMENT]: () => {
27
+ store.state.count -= 1;
28
+ },
21
29
  };
30
+ return actionsMap[action.payload.type]();
31
+ };
32
+ ```
33
+
34
+ ```javascript
35
+ import { useObservableStore } from "hermes-io";
36
+ import { store, storeId } from "@/store";
37
+ import reducer, { actions } from "@/reducer";
38
+
39
+ export default function App() {
40
+ useObservableStore(storeId, { count: 0 }, reducer, store);
41
+
42
+ const increment = () => store.mutate({ type: events.INCREMENT });
43
+
44
+ const decrement = () => store.mutate({ type: events.DECREMENT });
22
45
 
23
46
  return (
24
47
  <div>
@@ -29,35 +52,26 @@ function App({ notify }) {
29
52
  </div>
30
53
  );
31
54
  };
32
- export default withNotify(App, {
33
- context: CounterContext,
34
- observer: CounterObserver
35
- });
36
55
  ```
37
56
 
38
57
  ```javascript
39
- export function Counter() {
40
- const [count, setCount] = useState(0);
41
- const handleCounterNotification = (event) => {
42
- const { value = {} } = event;
43
- const { type } = value;
44
- if (type === INCREMENT) setCount((prevValue) => prevValue + 1);
45
- if (type === DECREMENT) setCount((prevValue) => prevValue - 1);
46
- };
58
+ import { useMutations } from "hermes-io";
59
+ import { store, storeId } from "@/store";
60
+ import { actions } from "@/reducer";
47
61
 
48
- useObserver({
49
- contexts: [CounterContext],
50
- observer: CounterObserver,
51
- listener: handleCounterNotification,
62
+ export function Counter() {
63
+ const { state, onEvent } = useMutations({
64
+ initialState: { count: 0 },
65
+ id: storeId,
66
+ store,
52
67
  });
68
+ onEvent(actions.INCREMENT, () => ({ count: state.count });
69
+ onEvent(actions.DECREMENT, () => ({ count: state.count });
53
70
 
54
- return <h1>Counter: {count}</h1>;
71
+ return <h1>Counter: {state.count}</h1>;
55
72
  }
56
73
  ```
57
- <img src="https://raw.githubusercontent.com/Maxtermax/hermes-io-counter-demo/master/src/assets/optimized.gif" />
58
-
59
- ## Documentation
60
- See: https://hermes-io-docs.vercel.app/
74
+ <img src="https://miro.medium.com/v2/resize:fit:1400/format:webp/1*VhOkr1735qdrHHyuJszqvQ.gif" />
61
75
 
62
76
 
63
77
  ## Devtool
@@ -1 +1 @@
1
- export*from"./useObserver";export*from"./useMutations";export*from"./useStore";export*from"./useStoreFactory";
1
+ export*from"./useObserver";export*from"./useMutations";export*from"./useStore";export*from"./useObservableStore";
@@ -0,0 +1 @@
1
+ import{useStore as r}from"./useStore";import{Context as e}from"../context/context";import{Observer as o}from"../observer/observer";import{Store as t}from"../store/store";export var useObservableStore=function(s,n,m,i){var c={store:new t({id:s,context:new e("Context_"+s),observer:new o}),reducer:m,data:n};return i&&(c.microStore=i),{store:r(c).store}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-io",
3
- "version": "2.9.74",
3
+ "version": "2.9.76",
4
4
  "description": "A lightweight React library that allows communication between Reactjs components by using the observer pattern and the hook api",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",