@reactunity/renderer 0.14.2 → 0.14.4

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.
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { createContext, createElement, useContext, useMemo, useRef } from 'react';
12
+ import { createContext, createElement, useContext, useMemo, useState } from 'react';
13
13
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
14
14
  import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
15
15
  /**
@@ -26,14 +26,13 @@ export function createDictionaryWatcher(dictionary, displayName) {
26
26
  return {
27
27
  subscribe: function (onStoreChange) {
28
28
  snapshot = (__assign({}, dictionary));
29
- var remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(function (key, value, dic) {
29
+ var remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(function () {
30
30
  var prev = snapshot;
31
31
  snapshot = (__assign({}, dictionary));
32
32
  if (!fields)
33
33
  onStoreChange();
34
34
  else {
35
- for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
36
- var field = fields_1[_i];
35
+ for (var it = fields.values(), field = null; field = it.next().value;) {
37
36
  if (isEqual ? !isEqual(prev[field], snapshot[field]) : (prev[field] !== snapshot[field])) {
38
37
  onStoreChange();
39
38
  break;
@@ -70,14 +69,25 @@ export function createDictionaryWatcher(dictionary, displayName) {
70
69
  }
71
70
  function useValue(subscribeToAllFields, fieldEqual) {
72
71
  if (subscribeToAllFields === void 0) { subscribeToAllFields = false; }
73
- var fields = useRef([]);
74
- var subscriber = useMemo(function () { return subscribeToAllFields ? defaultSubscriber : createSubscriber(fields.current, fieldEqual); }, [subscribeToAllFields, fieldEqual]);
72
+ var fields = useMemo(function () { return new Set(); }, []);
73
+ var _a = useState(false), allFieldsSubscribed = _a[0], setAllFieldsSubscribed = _a[1];
74
+ subscribeToAllFields || (subscribeToAllFields = allFieldsSubscribed);
75
+ var subscriber = useMemo(function () { return subscribeToAllFields ? defaultSubscriber : createSubscriber(fields, fieldEqual); }, [subscribeToAllFields, fieldEqual]);
75
76
  var value = useSyncExternalStore(subscriber.subscribe, subscriber.getSnapshot, subscriber.getSnapshot);
76
77
  var proxy = new Proxy(value, {
77
78
  get: function (target, p, receiver) {
78
- fields.current.push(p);
79
+ fields.add(p);
79
80
  return value[p];
80
81
  },
82
+ ownKeys: function (target) {
83
+ if (!allFieldsSubscribed)
84
+ setAllFieldsSubscribed(true);
85
+ return Reflect.ownKeys(target);
86
+ },
87
+ getOwnPropertyDescriptor: function (target, p) {
88
+ fields.add(p);
89
+ return __assign(__assign({}, Reflect.getOwnPropertyDescriptor(target, p)), { value: value[p] });
90
+ }
81
91
  });
82
92
  return proxy;
83
93
  }
@@ -7,7 +7,7 @@ function createSubscriber(obj, isEqual) {
7
7
  subscribe: function (onStoreChange) {
8
8
  snapshot = isWatchable ? obj.Value : undefined;
9
9
  var remove = isWatchable && typeof obj.AddListener === 'function' &&
10
- (obj === null || obj === void 0 ? void 0 : obj.AddListener(function (key, value, dic) {
10
+ (obj === null || obj === void 0 ? void 0 : obj.AddListener(function () {
11
11
  var prev = snapshot;
12
12
  snapshot = isWatchable ? obj.Value : undefined;
13
13
  if (typeof isEqual !== 'function' || !isEqual(prev, snapshot)) {
@@ -7,9 +7,11 @@ import { asyncReconciler } from './async/reconciler';
7
7
  import { isDevelopment } from './constants';
8
8
  import { syncReconciler } from './sync/reconciler';
9
9
  var containerMap = new Map();
10
+ var renderCount = 0;
10
11
  export var Renderer = {
11
12
  render: function (element, options) {
12
13
  if (options === void 0) { options = {}; }
14
+ renderCount++;
13
15
  var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
14
16
  var cacheKey = hostContainer.InstanceId >= 0 ? hostContainer.InstanceId : hostContainer;
15
17
  var isAsync = !(options === null || options === void 0 ? void 0 : options.disableBatchRendering);
@@ -38,7 +40,7 @@ export var Renderer = {
38
40
  }
39
41
  return Array.prototype.push.apply(commands_1, args);
40
42
  };
41
- var hostContainerInstance = {
43
+ var hostContainerInstance_1 = {
42
44
  type: 'native',
43
45
  commands: commands_1,
44
46
  component: hostContainer,
@@ -51,9 +53,9 @@ export var Renderer = {
51
53
  return;
52
54
  var serialized = JSON.stringify(commands_1);
53
55
  commands_1.length = 0;
54
- hostContainer.Context.FlushCommands(serialized);
56
+ hostContainerInstance_1.context.FlushCommands(serialized);
55
57
  };
56
- hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
58
+ hostRoot = asyncReconciler.createContainer(hostContainerInstance_1, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
57
59
  }
58
60
  else {
59
61
  hostRoot = syncReconciler.createContainer(hostContainer, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
@@ -64,6 +66,7 @@ export var Renderer = {
64
66
  if (shouldWrapWithHelpers) {
65
67
  var viewWrapperProps = {
66
68
  withHelpers: !(options === null || options === void 0 ? void 0 : options.disableHelpers),
69
+ renderCount: renderCount,
67
70
  };
68
71
  element = createElement(DefaultView, viewWrapperProps, element);
69
72
  }
@@ -1 +1 @@
1
- export declare const version = "0.14.2";
1
+ export declare const version = "0.14.4";
@@ -1 +1 @@
1
- export var version = '0.14.2';
1
+ export var version = '0.14.4';
@@ -2,6 +2,7 @@ import { ReactNode } from 'react';
2
2
  interface Props {
3
3
  children?: ReactNode;
4
4
  withHelpers: boolean;
5
+ renderCount: number;
5
6
  }
6
- export declare function DefaultView({ children, withHelpers }: Props): JSX.Element;
7
+ export declare function DefaultView({ children, withHelpers, renderCount }: Props): JSX.Element;
7
8
  export {};
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { ErrorBoundary } from './error-boundary';
3
3
  export function DefaultView(_a) {
4
- var children = _a.children, withHelpers = _a.withHelpers;
4
+ var children = _a.children, withHelpers = _a.withHelpers, renderCount = _a.renderCount;
5
5
  return _jsx(_Fragment, { children: !withHelpers ? children :
6
- _jsx(ErrorBoundary, { children: children }) });
6
+ _jsx(ErrorBoundary, { children: children }, renderCount) });
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactunity/renderer",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "description": "React renderer for Unity3D",
5
5
  "types": "dist/index.d.ts",
6
6
  "typings": "dist/index.d.ts",