@dcl/react-ecs 7.1.0 → 7.1.1-4386019452.commit-8b1daa0

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.
@@ -3,11 +3,19 @@ import Reconciler from 'react-reconciler';
3
3
  import { isListener } from '../components';
4
4
  import { CANVAS_ROOT_ENTITY } from '../components/uiTransform';
5
5
  import { componentKeys, isNotUndefined, noopConfig, propsChanged } from './utils';
6
+ function getPointerEnum(pointerKey) {
7
+ const pointers = {
8
+ onMouseDown: 1 /* PointerEventType.PET_DOWN */,
9
+ onMouseUp: 0 /* PointerEventType.PET_UP */
10
+ };
11
+ return pointers[pointerKey];
12
+ }
6
13
  export function createReconciler(engine, pointerEvents) {
7
14
  // Store all the entities so when we destroy the UI we can also destroy them
8
15
  const entities = new Set();
9
16
  // Store the onChange callbacks to be runned every time a Result has changed
10
17
  const changeEvents = new Map();
18
+ const clickEvents = new Map();
11
19
  // Initialize components
12
20
  const UiTransform = components.UiTransform(engine);
13
21
  const UiText = components.UiText(engine);
@@ -24,11 +32,18 @@ export function createReconciler(engine, pointerEvents) {
24
32
  uiInput: UiInput.componentId,
25
33
  uiDropdown: UiDropdown.componentId
26
34
  };
35
+ function pointerEventCallback(entity, pointerEvent) {
36
+ const callback = clickEvents.get(entity)?.get(pointerEvent);
37
+ if (callback)
38
+ callback();
39
+ return;
40
+ }
27
41
  function updateTree(instance, props) {
28
42
  upsertComponent(instance, props, 'uiTransform');
29
43
  }
30
44
  function upsertListener(instance, update) {
31
45
  if (update.type === 'delete' || !update.props) {
46
+ clickEvents.get(instance.entity)?.delete(getPointerEnum(update.component));
32
47
  if (update.component === 'onMouseDown') {
33
48
  pointerEvents.removeOnPointerDown(instance.entity);
34
49
  }
@@ -38,8 +53,14 @@ export function createReconciler(engine, pointerEvents) {
38
53
  return;
39
54
  }
40
55
  if (update.props) {
41
- const pointerEvent = update.component === 'onMouseDown' ? pointerEvents.onPointerDown : pointerEvents.onPointerUp;
42
- pointerEvent(instance.entity, update.props, {
56
+ const pointerEvent = getPointerEnum(update.component);
57
+ const entityEvent = clickEvents.get(instance.entity) || clickEvents.set(instance.entity, new Map()).get(instance.entity);
58
+ const alreadyHasPointerEvent = entityEvent.get(pointerEvent);
59
+ entityEvent.set(pointerEvent, update.props);
60
+ if (alreadyHasPointerEvent)
61
+ return;
62
+ const pointerEventSystem = update.component === 'onMouseDown' ? pointerEvents.onPointerDown : pointerEvents.onPointerUp;
63
+ pointerEventSystem(instance.entity, () => pointerEventCallback(instance.entity, pointerEvent), {
43
64
  button: 0 /* InputAction.IA_POINTER */,
44
65
  // We add this showFeedBack so the pointerEventSystem creates a PointerEvent component with our entity
45
66
  // This is needed for the renderer to know which entities are clickeables
@@ -52,20 +73,22 @@ export function createReconciler(engine, pointerEvents) {
52
73
  const Component = engine.getComponent(componentId);
53
74
  Component.deleteFrom(instance.entity);
54
75
  }
55
- function upsertComponent(instance, props, componentName) {
76
+ function upsertComponent(instance, props = {}, componentName) {
56
77
  const componentId = getComponentId[componentName];
57
- const Component = engine.getComponent(componentId);
58
- const component = Component.getMutableOrNull(instance.entity) || Component.create(instance.entity);
78
+ if ('onChange' in props) {
79
+ const onChange = props['onChange'];
80
+ updateOnChange(instance.entity, componentId, { fn: onChange });
81
+ delete props['onChange'];
82
+ }
83
+ // We check if there is any key pending to be changed to avoid updating the existing component
84
+ if (!Object.keys(props).length) {
85
+ return;
86
+ }
87
+ const ComponentDef = engine.getComponent(componentId);
88
+ const component = ComponentDef.getMutableOrNull(instance.entity) || ComponentDef.create(instance.entity);
59
89
  for (const key in props) {
60
90
  const keyProp = key;
61
- if (key === 'onChange') {
62
- const onChange = props[keyProp];
63
- updateOnChange(instance.entity, componentId, { fn: onChange });
64
- }
65
- else {
66
- ;
67
- component[keyProp] = props[keyProp];
68
- }
91
+ component[keyProp] = props[keyProp];
69
92
  }
70
93
  }
71
94
  function removeChildEntity(instance) {
@@ -169,7 +192,7 @@ export function createReconciler(engine, pointerEvents) {
169
192
  if (update.type === 'delete') {
170
193
  removeComponent(instance, update.component);
171
194
  }
172
- else {
195
+ else if (update.props) {
173
196
  upsertComponent(instance, update.props, update.component);
174
197
  }
175
198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcl/react-ecs",
3
- "version": "7.1.0",
3
+ "version": "7.1.1-4386019452.commit-8b1daa0",
4
4
  "description": "Decentraland ECS",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@types/react-reconciler": "^0.28.0"
29
29
  },
30
30
  "dependencies": {
31
- "@dcl/ecs": "7.1.0",
31
+ "@dcl/ecs": "7.1.1-4386019452.commit-8b1daa0",
32
32
  "react": "^18.2.0",
33
33
  "react-reconciler": "^0.29.0"
34
34
  },
@@ -42,5 +42,5 @@
42
42
  "displayName": "React ECS",
43
43
  "tsconfig": "./tsconfig.json"
44
44
  },
45
- "commit": "e8aeb07d8dc9bf6eb1b021853d9957ed2828c1e4"
45
+ "commit": "8b1daa095e12f588f917054be41cfad6da952487"
46
46
  }