@dcl/react-ecs 7.17.1-20863678121.commit-2175acc → 7.17.1-21217092165.commit-1c2ff72

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/system.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IEngine, PointerEventsSystem } from '@dcl/ecs';
1
+ import { type Entity, type IEngine, type PointerEventsSystem } from '@dcl/ecs';
2
2
  import type { ReactEcs } from './react-ecs';
3
3
  /**
4
4
  * @public
@@ -10,6 +10,25 @@ export type UiComponent = () => ReactEcs.JSX.ReactNode;
10
10
  export interface ReactBasedUiSystem {
11
11
  destroy(): void;
12
12
  setUiRenderer(ui: UiComponent): void;
13
+ /**
14
+ * Add a UI renderer associated with an entity. The UI will be automatically cleaned up
15
+ * when the entity is removed from the engine.
16
+ *
17
+ * If a renderer is already associated with the given entity, it will be replaced.
18
+ *
19
+ * This allows dynamically adding UI Renderers that are rendered alongside the main
20
+ * UI set via setUiRenderer().
21
+ *
22
+ * @param entity - The entity to associate with this UI renderer. When the entity is removed,
23
+ * the UI renderer is automatically cleaned up.
24
+ * @param ui - The UI component to render
25
+ */
26
+ addUiRenderer(entity: Entity, ui: UiComponent): void;
27
+ /**
28
+ * Remove a previously added UI renderer by its associated entity.
29
+ * @param entity - The entity whose UI renderer should be removed
30
+ */
31
+ removeUiRenderer(entity: Entity): void;
13
32
  }
14
33
  /**
15
34
  * @public
package/dist/system.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { EntityState } from '@dcl/ecs';
1
2
  import React from 'react';
2
3
  import { createReconciler } from './reconciler';
3
4
  /**
@@ -6,9 +7,34 @@ import { createReconciler } from './reconciler';
6
7
  export function createReactBasedUiSystem(engine, pointerSystem) {
7
8
  const renderer = createReconciler(engine, pointerSystem);
8
9
  let uiComponent = undefined;
10
+ const additionalRenderers = new Map();
9
11
  function ReactBasedUiSystem() {
10
- if (uiComponent)
11
- renderer.update(React.createElement(uiComponent));
12
+ const components = [];
13
+ // Add main UI component
14
+ if (uiComponent) {
15
+ components.push(React.createElement(uiComponent, { key: '__main__' }));
16
+ }
17
+ const entitiesToRemove = [];
18
+ for (const [entity, component] of additionalRenderers) {
19
+ // Check for entity-based cleanup
20
+ if (engine.getEntityState(entity) === EntityState.Removed) {
21
+ entitiesToRemove.push(entity);
22
+ }
23
+ else {
24
+ components.push(React.createElement(component, { key: `__entity_${entity}__` }));
25
+ }
26
+ }
27
+ // Entity-based cleanup
28
+ for (const entity of entitiesToRemove) {
29
+ additionalRenderers.delete(entity);
30
+ }
31
+ // Always update the renderer - pass null when empty to clear the UI
32
+ if (components.length > 0) {
33
+ renderer.update(React.createElement(React.Fragment, null, ...components));
34
+ }
35
+ else {
36
+ renderer.update(null);
37
+ }
12
38
  }
13
39
  engine.addSystem(ReactBasedUiSystem, 100e3, '@dcl/react-ecs');
14
40
  return {
@@ -20,6 +46,12 @@ export function createReactBasedUiSystem(engine, pointerSystem) {
20
46
  },
21
47
  setUiRenderer(ui) {
22
48
  uiComponent = ui;
49
+ },
50
+ addUiRenderer(entity, ui) {
51
+ additionalRenderers.set(entity, ui);
52
+ },
53
+ removeUiRenderer(entity) {
54
+ additionalRenderers.delete(entity);
23
55
  }
24
56
  };
25
57
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dcl/react-ecs",
3
3
  "description": "Decentraland ECS",
4
- "version": "7.17.1-20863678121.commit-2175acc",
4
+ "version": "7.17.1-21217092165.commit-1c2ff72",
5
5
  "author": "DCL",
6
6
  "bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
7
7
  "dependencies": {
8
- "@dcl/ecs": "7.17.1-20863678121.commit-2175acc",
8
+ "@dcl/ecs": "7.17.1-21217092165.commit-1c2ff72",
9
9
  "react": "^18.2.0",
10
10
  "react-reconciler": "^0.29.0"
11
11
  },
@@ -40,5 +40,5 @@
40
40
  "tsconfig": "./tsconfig.json"
41
41
  },
42
42
  "types": "./dist/index.d.ts",
43
- "commit": "2175accb2882cae9e2a15976235a1bced8e43b0f"
43
+ "commit": "1c2ff7242cd11eb981666a8318f670c0b302813b"
44
44
  }