@hitachivantara/app-shell-services 1.1.0 → 1.1.2
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.
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
import { useState, useEffect, createContext, useMemo, useContext, useCallback, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { useState, useEffect, createElement, createContext, useMemo, useContext, useCallback, useRef } from "react";
|
|
2
|
+
function isEqual(a, b) {
|
|
3
|
+
if (a === b) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
if (a == null || b == null || typeof a !== typeof b || typeof a !== "object" || Array.isArray(a) !== Array.isArray(b)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
10
|
+
if (a.length !== b.length) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return a.every((item, index) => isEqual(item, b[index]));
|
|
14
|
+
}
|
|
15
|
+
const keysA = Object.keys(a);
|
|
16
|
+
const keysB = Object.keys(b);
|
|
17
|
+
if (keysA.length !== keysB.length) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return keysA.every(
|
|
21
|
+
(key) => isEqual(
|
|
22
|
+
a[key],
|
|
23
|
+
b[key]
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
4
27
|
function useAsync(promiseFactory, options) {
|
|
5
28
|
const dataProp = options?.dataProp ?? "data";
|
|
6
29
|
const pendingData = options?.pendingData;
|
|
@@ -206,7 +229,7 @@ function createServiceReference(serviceId, serviceConfig) {
|
|
|
206
229
|
function bindComponent(Component, configProps) {
|
|
207
230
|
const BoundComponent = (props) => {
|
|
208
231
|
const mergedProps = { ...configProps, ...props };
|
|
209
|
-
return
|
|
232
|
+
return createElement(Component, mergedProps);
|
|
210
233
|
};
|
|
211
234
|
return BoundComponent;
|
|
212
235
|
}
|
|
@@ -290,7 +313,11 @@ const ServicesContext = createContext(
|
|
|
290
313
|
);
|
|
291
314
|
const ServiceManagerProvider = ({ config, children }) => {
|
|
292
315
|
const serviceManager = useMemo(() => createServiceManager(config), [config]);
|
|
293
|
-
return
|
|
316
|
+
return createElement(
|
|
317
|
+
ServicesContext.Provider,
|
|
318
|
+
{ value: serviceManager },
|
|
319
|
+
children
|
|
320
|
+
);
|
|
294
321
|
};
|
|
295
322
|
const useServicesContext = () => {
|
|
296
323
|
const context = useContext(ServicesContext);
|
|
@@ -304,7 +331,7 @@ const useServicesContext = () => {
|
|
|
304
331
|
function useDeepMemo(value) {
|
|
305
332
|
const ref = useRef();
|
|
306
333
|
if (!isEqual(value, ref.current)) {
|
|
307
|
-
ref.current =
|
|
334
|
+
ref.current = structuredClone(value);
|
|
308
335
|
}
|
|
309
336
|
return ref.current;
|
|
310
337
|
}
|
package/dist/esm/hooks/Hooks.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useCallback, useRef } from "react";
|
|
2
|
-
import { isEqual
|
|
2
|
+
import { isEqual } from "../utils/isEqual.js";
|
|
3
3
|
import { useAsync } from "./useAsync.js";
|
|
4
4
|
import { useServicesContext } from "./useServicesContext.js";
|
|
5
5
|
function useDeepMemo(value) {
|
|
6
6
|
const ref = useRef();
|
|
7
7
|
if (!isEqual(value, ref.current)) {
|
|
8
|
-
ref.current =
|
|
8
|
+
ref.current = structuredClone(value);
|
|
9
9
|
}
|
|
10
10
|
return ref.current;
|
|
11
11
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext, useMemo } from "react";
|
|
1
|
+
import { createContext, useMemo, createElement } from "react";
|
|
3
2
|
import { createServiceReference } from "../utils/serviceReference.js";
|
|
4
3
|
function createServiceReferenceMap(services = {}) {
|
|
5
4
|
return Object.entries(services).reduce(
|
|
@@ -81,7 +80,11 @@ const ServicesContext = createContext(
|
|
|
81
80
|
);
|
|
82
81
|
const ServiceManagerProvider = ({ config, children }) => {
|
|
83
82
|
const serviceManager = useMemo(() => createServiceManager(config), [config]);
|
|
84
|
-
return
|
|
83
|
+
return createElement(
|
|
84
|
+
ServicesContext.Provider,
|
|
85
|
+
{ value: serviceManager },
|
|
86
|
+
children
|
|
87
|
+
);
|
|
85
88
|
};
|
|
86
89
|
export {
|
|
87
90
|
ServicesContext,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function isEqual(a, b) {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (a == null || b == null || typeof a !== typeof b || typeof a !== "object" || Array.isArray(a) !== Array.isArray(b)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
9
|
+
if (a.length !== b.length) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return a.every((item, index) => isEqual(item, b[index]));
|
|
13
|
+
}
|
|
14
|
+
const keysA = Object.keys(a);
|
|
15
|
+
const keysB = Object.keys(b);
|
|
16
|
+
if (keysA.length !== keysB.length) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return keysA.every(
|
|
20
|
+
(key) => isEqual(
|
|
21
|
+
a[key],
|
|
22
|
+
b[key]
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
isEqual
|
|
28
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement } from "react";
|
|
2
2
|
function createServiceReferenceBase(serviceId, serviceConfig, getService) {
|
|
3
3
|
return {
|
|
4
4
|
serviceId,
|
|
@@ -157,7 +157,7 @@ function createServiceReference(serviceId, serviceConfig) {
|
|
|
157
157
|
function bindComponent(Component, configProps) {
|
|
158
158
|
const BoundComponent = (props) => {
|
|
159
159
|
const mergedProps = { ...configProps, ...props };
|
|
160
|
-
return
|
|
160
|
+
return createElement(Component, mergedProps);
|
|
161
161
|
};
|
|
162
162
|
return BoundComponent;
|
|
163
163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/app-shell-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Hitachi Vantara UI Kit Team",
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
"directory": "packages/app-shell-services"
|
|
15
15
|
},
|
|
16
16
|
"bugs": "https://github.com/lumada-design/hv-uikit-react/issues",
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"lodash": "^4.17.21"
|
|
19
|
-
},
|
|
20
17
|
"peerDependencies": {
|
|
21
18
|
"react": "^18.2.0"
|
|
22
19
|
},
|
|
@@ -36,7 +33,7 @@
|
|
|
36
33
|
"access": "public",
|
|
37
34
|
"directory": "package"
|
|
38
35
|
},
|
|
39
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "7beb41faed7988ae23de7802faa1b637504c7c9a",
|
|
40
37
|
"types": "./dist/types/index.d.ts",
|
|
41
38
|
"module": "dist/esm/index.js"
|
|
42
39
|
}
|