hermes-io 2.2.0 → 2.2.3
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/context.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let isDevtoolsInitialized = false;
|
|
1
2
|
let recording = false;
|
|
2
3
|
let collection = [];
|
|
3
4
|
|
|
@@ -24,7 +25,14 @@ const handleMessageFromDevtools = (event) => {
|
|
|
24
25
|
}
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
export const enableDevTools = () => {
|
|
30
|
+
if (!isDevtoolsInitialized) {
|
|
31
|
+
window.addEventListener("message", handleMessageFromDevtools);
|
|
32
|
+
isDevtoolsInitialized = true;
|
|
33
|
+
}
|
|
34
|
+
return isDevtoolsInitialized;
|
|
35
|
+
};
|
|
28
36
|
|
|
29
37
|
export class Context {
|
|
30
38
|
id = null;
|
|
@@ -44,10 +44,9 @@ function App() {
|
|
|
44
44
|
setProducts([...productsStore.get('collection')]);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
const handleAddProduct = ({ value: product = {} }
|
|
47
|
+
const handleAddProduct = ({ value: product = {} }) => {
|
|
48
48
|
product.selected = true;
|
|
49
49
|
setProducts([...productsStore.get('collection')]);
|
|
50
|
-
resolve();
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
useObserver({
|
|
@@ -15,9 +15,8 @@ import * as contexts from "@contexts";
|
|
|
15
15
|
const Products = (props = {}) => {
|
|
16
16
|
const { data = [] } = props;
|
|
17
17
|
|
|
18
|
-
const handleAddProduct =
|
|
19
|
-
|
|
20
|
-
console.log({ result });
|
|
18
|
+
const handleAddProduct = (product = {}) => {
|
|
19
|
+
ProductsObserver.add.notify({ value: product, context: contexts.products });
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
const handleRemoveProduct = (product = {}) => {
|
package/hooks/useObserver.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
|
+
import { enableDevTools } from "../context";
|
|
2
3
|
|
|
3
4
|
export const useObserver = (props = {}) => {
|
|
4
5
|
useEffect(() => {
|
|
@@ -7,7 +8,9 @@ export const useObserver = (props = {}) => {
|
|
|
7
8
|
const hasfromList = contexts.length !== 0;
|
|
8
9
|
const hasValidList = hasfromList && contexts.find((ctx) => ctx.id === payload?.context?.id);
|
|
9
10
|
if (hasValidList) {
|
|
10
|
-
|
|
11
|
+
if (!enableDevTools()) {
|
|
12
|
+
payload?.context?.update({ value: payload, listener });
|
|
13
|
+
}
|
|
11
14
|
listener?.(payload, resolve);
|
|
12
15
|
}
|
|
13
16
|
}
|
package/package.json
CHANGED