@remvst/game-navigation-react 1.0.2 → 1.4.1

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/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './react-game-plugin';
2
- export * from './react-screen';
1
+ export * from "./react-game-plugin";
2
+ export * from "./react-screen";
@@ -9,4 +9,4 @@ class ReactGamePlugin extends game_navigation_core_1.GamePlugin {
9
9
  }
10
10
  }
11
11
  exports.ReactGamePlugin = ReactGamePlugin;
12
- ReactGamePlugin.key = 'react';
12
+ ReactGamePlugin.key = "react";
@@ -1,12 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { HTMLScreen } from '@remvst/game-navigation-html';
2
+ import { HTMLScreen } from "@remvst/game-navigation-html";
3
3
  export declare abstract class ReactScreen extends HTMLScreen {
4
4
  private root;
5
5
  private rootContainer;
6
6
  abstract rootComponent(): Promise<React.ReactElement>;
7
7
  setup(): void;
8
- foreground(): void;
9
- background(): void;
10
8
  destroy(): void;
11
9
  rebuild(): void;
12
10
  }
@@ -1,41 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReactScreen = void 0;
4
- const client_1 = require("react-dom/client");
5
4
  const game_navigation_html_1 = require("@remvst/game-navigation-html");
5
+ const client_1 = require("react-dom/client");
6
6
  class ReactScreen extends game_navigation_html_1.HTMLScreen {
7
7
  constructor() {
8
8
  super(...arguments);
9
- this.rootContainer = document.createElement('div');
9
+ this.rootContainer = document.createElement("div");
10
10
  }
11
11
  setup() {
12
12
  super.setup();
13
13
  this.root = (0, client_1.createRoot)(this.rootContainer);
14
- this.rootComponent().then(component => {
14
+ this.rootComponent().then((component) => {
15
15
  this.root?.render(component);
16
16
  });
17
- this.rootContainer.style.width = '100%';
18
- this.rootContainer.style.height = '100%';
19
- }
20
- foreground() {
21
- super.foreground();
22
- this.view.style.display = 'block';
17
+ this.rootContainer.style.width = "100%";
18
+ this.rootContainer.style.height = "100%";
23
19
  this.view.appendChild(this.rootContainer);
24
20
  }
25
- background() {
26
- super.background();
27
- this.view.style.display = 'none';
28
- this.rootContainer.parentNode?.removeChild(this.rootContainer);
29
- }
30
21
  destroy() {
31
22
  super.destroy();
32
- this.root.unmount();
23
+ this.root?.unmount();
33
24
  this.root = null;
34
25
  }
35
26
  rebuild() {
36
- this.root.unmount();
37
- this.root = (0, client_1.createRoot)(this.rootContainer);
38
- this.rootComponent().then(component => this.root.render(component));
27
+ this.root?.unmount();
28
+ const root = (0, client_1.createRoot)(this.rootContainer);
29
+ this.root = root;
30
+ this.rootComponent().then((component) => {
31
+ if (this.root !== root)
32
+ return;
33
+ this.root?.render(component);
34
+ });
39
35
  }
40
36
  }
41
37
  exports.ReactScreen = ReactScreen;
package/package.json CHANGED
@@ -1,24 +1,22 @@
1
1
  {
2
2
  "name": "@remvst/game-navigation-react",
3
- "version": "1.0.2",
3
+ "version": "1.4.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "build": "rm -rf lib && tsc",
8
- "prepublishOnly": "npm i && npm run build"
7
+ "build": "rm -rf lib && tsc",
8
+ "prepublishOnly": "npm i && npm run build"
9
9
  },
10
10
  "author": "Rémi Vansteelandt",
11
11
  "license": "UNLICENSED",
12
- "dependencies": {
13
- "@types/react-dom": "^18.2.0",
14
- "react": "^18.2.0",
15
- "react-dom": "^18.2.0"
16
- },
17
12
  "peerDependencies": {
18
- "@remvst/game-navigation-core": "^1.0.1",
19
- "@remvst/game-navigation-html": "^1.0.1"
13
+ "@remvst/game-navigation-core": "^1.4.x",
14
+ "@remvst/game-navigation-html": "^1.4.x",
15
+ "@types/react-dom": "^18.2.0",
16
+ "react": "^18.2.0",
17
+ "react-dom": "^18.2.0"
20
18
  },
21
19
  "devDependencies": {
22
- "typescript": "^5.2.2"
20
+ "typescript": "^5.2.2"
23
21
  }
24
- }
22
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './react-game-plugin';
2
- export * from './react-screen';
1
+ export * from "./react-game-plugin";
2
+ export * from "./react-screen";
@@ -1,6 +1,6 @@
1
1
  import { GamePlugin } from "@remvst/game-navigation-core";
2
2
 
3
3
  export class ReactGamePlugin extends GamePlugin {
4
- static readonly key = 'react';
4
+ static readonly key = "react";
5
5
  readonly key = ReactGamePlugin.key;
6
6
  }
@@ -1,10 +1,9 @@
1
- import { createRoot, Root } from 'react-dom/client';
2
- import { HTMLScreen } from '@remvst/game-navigation-html';
1
+ import { HTMLScreen } from "@remvst/game-navigation-html";
2
+ import { createRoot, Root } from "react-dom/client";
3
3
 
4
4
  export abstract class ReactScreen extends HTMLScreen {
5
-
6
5
  private root: Root;
7
- private rootContainer = document.createElement('div');
6
+ private rootContainer = document.createElement("div");
8
7
 
9
8
  abstract rootComponent(): Promise<React.ReactElement>;
10
9
 
@@ -12,35 +11,31 @@ export abstract class ReactScreen extends HTMLScreen {
12
11
  super.setup();
13
12
 
14
13
  this.root = createRoot(this.rootContainer);
15
- this.rootComponent().then(component => {
14
+ this.rootComponent().then((component) => {
16
15
  this.root?.render(component);
17
16
  });
18
17
 
19
- this.rootContainer.style.width = '100%';
20
- this.rootContainer.style.height = '100%';
21
- }
18
+ this.rootContainer.style.width = "100%";
19
+ this.rootContainer.style.height = "100%";
22
20
 
23
- foreground(): void {
24
- super.foreground();
25
- this.view.style.display = 'block';
26
21
  this.view.appendChild(this.rootContainer);
27
22
  }
28
23
 
29
- background(): void {
30
- super.background();
31
- this.view.style.display = 'none';
32
- this.rootContainer.parentNode?.removeChild(this.rootContainer);
33
- }
34
-
35
24
  destroy() {
36
25
  super.destroy();
37
- this.root.unmount();
26
+ this.root?.unmount();
38
27
  this.root = null;
39
28
  }
40
29
 
41
30
  rebuild() {
42
- this.root.unmount();
43
- this.root = createRoot(this.rootContainer);
44
- this.rootComponent().then(component => this.root.render(component));
31
+ this.root?.unmount();
32
+
33
+ const root = createRoot(this.rootContainer);
34
+ this.root = root;
35
+
36
+ this.rootComponent().then((component) => {
37
+ if (this.root !== root) return;
38
+ this.root?.render(component);
39
+ });
45
40
  }
46
41
  }