@reactunity/renderer 0.9.2 → 0.10.0
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/dist/src/helpers/dictionary-watcher.d.ts +14 -2
- package/dist/src/helpers/dictionary-watcher.js +28 -21
- package/dist/src/helpers/watcher.js +10 -11
- package/dist/src/models/environment/index.d.ts +1 -0
- package/dist/src/models/generated/react.d.ts +398 -83
- package/dist/src/models/generated/react.js +1 -1
- package/dist/src/models/properties/styles.d.ts +6 -6
- package/dist/src/renderer/async/callbacks.d.ts +6 -0
- package/dist/src/renderer/async/callbacks.js +38 -0
- package/dist/src/renderer/async/commands.d.ts +45 -0
- package/dist/src/renderer/async/commands.js +1 -0
- package/dist/src/renderer/async/objects.d.ts +8 -0
- package/dist/src/renderer/async/objects.js +31 -0
- package/dist/src/renderer/async/reconciler.d.ts +9 -0
- package/dist/src/renderer/async/reconciler.js +135 -0
- package/dist/src/renderer/async/types.d.ts +19 -0
- package/dist/src/renderer/async/types.js +1 -0
- package/dist/src/renderer/constants.d.ts +23 -0
- package/dist/src/renderer/constants.js +49 -0
- package/dist/src/renderer/diffing.js +39 -13
- package/dist/src/renderer/renderer.d.ts +9 -1
- package/dist/src/renderer/renderer.js +73 -111
- package/dist/src/renderer/sync/reconciler.d.ts +2 -0
- package/dist/src/renderer/sync/reconciler.js +35 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +1 -0
- package/dist/src/views/default-view.d.ts +2 -1
- package/dist/src/views/default-view.js +4 -3
- package/dist/src/views/error-boundary.d.ts +1 -1
- package/dist/src/views/error-boundary.js +1 -1
- package/package.json +9 -9
- package/version.js +3 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { ReactUnity } from '../models/generated';
|
|
3
2
|
export interface DictionaryWatcher<T = Record<string, any>> {
|
|
4
3
|
/** React Context that provides the value */
|
|
@@ -30,6 +29,19 @@ export interface DictionaryWatcher<T = Record<string, any>> {
|
|
|
30
29
|
* ```
|
|
31
30
|
*/
|
|
32
31
|
useContext: () => T;
|
|
32
|
+
/**
|
|
33
|
+
* React Hook for getting a partial value from Context
|
|
34
|
+
*
|
|
35
|
+
* Usage:
|
|
36
|
+
*
|
|
37
|
+
* ```tsx
|
|
38
|
+
* function App() {
|
|
39
|
+
* const values = watcher.useSelector(st => st.count);
|
|
40
|
+
* ...
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
useSelector<Res>(selector: (store: T) => Res): Res;
|
|
33
45
|
}
|
|
34
46
|
/**
|
|
35
47
|
* Creates a context that updates its value when the values in the dictionary change
|
|
@@ -41,4 +53,4 @@ export declare const globalsWatcher: DictionaryWatcher<DefaultGlobals>;
|
|
|
41
53
|
export declare const useGlobals: () => DefaultGlobals;
|
|
42
54
|
export declare const GlobalsProvider: (props: {
|
|
43
55
|
children?: React.ReactNode;
|
|
44
|
-
}) =>
|
|
56
|
+
}) => import("react").FunctionComponentElement<import("react").ProviderProps<DefaultGlobals>>;
|
|
@@ -9,37 +9,44 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import
|
|
12
|
+
import { createContext, createElement, useContext } from 'react';
|
|
13
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
14
|
+
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
13
15
|
/**
|
|
14
16
|
* Creates a context that updates its value when the values in the dictionary change
|
|
15
17
|
* @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
|
|
16
18
|
* @param displayName A displayName to identify this context easier in case of problems
|
|
17
19
|
*/
|
|
18
20
|
export function createDictionaryWatcher(dictionary, displayName) {
|
|
19
|
-
var ctx =
|
|
21
|
+
var ctx = createContext(undefined);
|
|
20
22
|
if (displayName)
|
|
21
23
|
ctx.displayName = displayName;
|
|
24
|
+
var snapshot = (__assign({}, dictionary));
|
|
25
|
+
var subscribe = function (onStoreChange) {
|
|
26
|
+
snapshot = (__assign({}, dictionary));
|
|
27
|
+
var remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(function (key, value, dic) {
|
|
28
|
+
snapshot = (__assign({}, dictionary));
|
|
29
|
+
onStoreChange();
|
|
30
|
+
});
|
|
31
|
+
if (!remove) {
|
|
32
|
+
if (displayName)
|
|
33
|
+
console.warn("".concat(displayName, " dictionary does not provide a change listener"));
|
|
34
|
+
else
|
|
35
|
+
console.warn('The dictionary does not provide a change listener');
|
|
36
|
+
}
|
|
37
|
+
return function () { return remove === null || remove === void 0 ? void 0 : remove(); };
|
|
38
|
+
};
|
|
39
|
+
var getSnapshot = function () { return snapshot; };
|
|
22
40
|
var Provider = function GlobalsProvider(_a) {
|
|
23
41
|
var children = _a.children;
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
var remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(function (key, value, dic) {
|
|
27
|
-
setRender(function (x) { return x + 1; });
|
|
28
|
-
});
|
|
29
|
-
if (!remove) {
|
|
30
|
-
if (displayName)
|
|
31
|
-
console.warn("".concat(displayName, " dictionary does not provide a change listener"));
|
|
32
|
-
else
|
|
33
|
-
console.warn('The dictionary does not provide a change listener');
|
|
34
|
-
}
|
|
35
|
-
return function () { return remove === null || remove === void 0 ? void 0 : remove(); };
|
|
36
|
-
}, []);
|
|
37
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
-
var value = React.useMemo(function () { return (__assign({}, dictionary)); }, [render]);
|
|
39
|
-
return React.createElement(ctx.Provider, { value: value }, children);
|
|
42
|
+
var value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
43
|
+
return createElement(ctx.Provider, { value: value }, children);
|
|
40
44
|
};
|
|
41
|
-
function
|
|
42
|
-
|
|
45
|
+
function useSelector(selector) {
|
|
46
|
+
return useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, selector);
|
|
47
|
+
}
|
|
48
|
+
function useDictionaryContext() {
|
|
49
|
+
var context = useContext(ctx);
|
|
43
50
|
if (context === undefined) {
|
|
44
51
|
if (displayName)
|
|
45
52
|
throw new Error("".concat(displayName, ".useContext must be used within a ").concat(displayName, ".Provider"));
|
|
@@ -48,7 +55,7 @@ export function createDictionaryWatcher(dictionary, displayName) {
|
|
|
48
55
|
}
|
|
49
56
|
return context;
|
|
50
57
|
}
|
|
51
|
-
return { context: ctx, Provider: Provider, useContext:
|
|
58
|
+
return { context: ctx, Provider: Provider, useContext: useDictionaryContext, useSelector: useSelector };
|
|
52
59
|
}
|
|
53
60
|
export var globalsWatcher = createDictionaryWatcher(Globals, 'globalsContext');
|
|
54
61
|
export var useGlobals = globalsWatcher.useContext;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
2
3
|
export function useWatchable(obj) {
|
|
3
|
-
var isWatchable = obj && typeof obj === 'object' && ('Value' in obj);
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return;
|
|
4
|
+
var isWatchable = useMemo(function () { return obj && typeof obj === 'object' && ('Value' in obj); }, [obj]);
|
|
5
|
+
var subscribe = useCallback(function (onStoreChange) {
|
|
6
|
+
if (isWatchable && 'AddListener' in obj) {
|
|
7
|
+
var unsub_1 = obj.AddListener(function () { return onStoreChange(); });
|
|
8
|
+
return function () { return unsub_1 === null || unsub_1 === void 0 ? void 0 : unsub_1(); };
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
if ('AddListener' in obj)
|
|
12
|
-
return obj.AddListener(function (val) { return setState(val); });
|
|
10
|
+
return function () { };
|
|
13
11
|
}, [obj, isWatchable]);
|
|
14
|
-
return
|
|
12
|
+
var getSnapshot = useCallback(function () { return isWatchable ? obj.Value : undefined; }, [obj, isWatchable]);
|
|
13
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
15
14
|
}
|