hermes-io 2.2.11 → 2.2.13

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/. quokka CHANGED
@@ -10,7 +10,6 @@
10
10
  ],
11
11
  "alias": {
12
12
  "@core": "./src/core",
13
- "@components": "./src/core/components",
14
13
  "@contexts": "./src/core/contexts",
15
14
  "@factory": "./src/core/factory",
16
15
  "@hooks": "./src/core/hooks",
package/README.md CHANGED
@@ -10,8 +10,7 @@ A lightweight javascript library that allows communication between components by
10
10
  - [notify](#notify)
11
11
  - Devtools (TODO)
12
12
 
13
- [DevTools Preview](https://www.youtube.com/watch?v=OSL9ob56urw)
14
-
13
+ ![DevTools Preview](https://raw.githubusercontent.com/Maxtermax/hermes-io-devtools/master/demo.gif)
15
14
 
16
15
  # Installation
17
16
  ```
package/hooks/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from './useObserver';
2
+ export * from './useProxy';
@@ -3,7 +3,7 @@ import React, { useEffect } from "react";
3
3
  export const useObserver = (props = {}) => {
4
4
  useEffect(() => {
5
5
  const { observer, listener, contexts = [] } = props;
6
- function handleAction(payload, resolve) {
6
+ function subscriber(payload, resolve) {
7
7
  const hasfromList = contexts.length !== 0;
8
8
  const hasValidList = hasfromList && contexts.find((ctx) => ctx.id === payload?.context?.id);
9
9
  if (hasValidList) {
@@ -11,7 +11,7 @@ export const useObserver = (props = {}) => {
11
11
  listener?.(payload, resolve);
12
12
  }
13
13
  }
14
- observer.subscribe(handleAction);
15
- return () => observer.unsubscribe(handleAction);
14
+ observer?.subscribe?.(subscriber);
15
+ return () => observer?.unsubscribe?.(subscriber);
16
16
  }, [props]);
17
17
  };
@@ -0,0 +1,32 @@
1
+ import React, { useEffect, useState, useRef } from "react";
2
+ import { useObserver } from './useObserver';
3
+
4
+ export const useProxy = (target, options) => {
5
+ const proxyRef = useRef({ ...target });
6
+ const [value, setValue] = useState(target);
7
+ useObserver({
8
+ observer: options?.observer,
9
+ contexts: options?.contexts,
10
+ listener: (payload) => value[payload.value],
11
+ })
12
+ useEffect(() => {
13
+ function setup() {
14
+ const handler = {
15
+ get: function (_target, prop) {
16
+ return value[prop];
17
+ },
18
+ set: function (target, prop, newValue) {
19
+ target[prop] = newValue;
20
+ setValue({ ...target });
21
+ options?.contexts?.forEach?.((context) =>
22
+ options?.observer?.notify?.({ value: proxyRef, context })
23
+ );
24
+ return true;
25
+ },
26
+ };
27
+ proxyRef.current = new Proxy(target, handler);
28
+ }
29
+ setup();
30
+ }, [target, setValue, proxyRef, value, options]);
31
+ return proxyRef;
32
+ };
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from "./hooks";
2
- export * from "./components";
3
2
  export * from "./main";
4
3
  export * from "./context";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-io",
3
- "version": "2.2.11",
3
+ "version": "2.2.13",
4
4
  "description": "A lightweight javascript library that allows communication between Reactjs components by using the observer pattern and the hook api",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
-
3
- export const withActions = (actions, Component) => (props = {}) => <Component actions={actions} {...props}/>;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
-
3
- export const withStore = (store, Component) => (props = {}) => <Component store={store} {...props}/>;
@@ -1,3 +0,0 @@
1
- export * from './WithActions';
2
- export * from './WithStore';
3
-