@remvst/game-navigation-core 1.8.4 → 1.9.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/game/game.js CHANGED
@@ -24,7 +24,13 @@ class Game {
24
24
  this.pluginMap.set(plugin.key, plugin);
25
25
  }
26
26
  for (const plugin of this.plugins) {
27
- plugin.setup();
27
+ try {
28
+ plugin.setup();
29
+ }
30
+ catch (err) {
31
+ console.error(`Failed to setup ${plugin.key} plugin: ${err.message}`, err);
32
+ throw err;
33
+ }
28
34
  }
29
35
  this.lastFrame = window.performance.now();
30
36
  this.scheduleFrame();
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Resolver = exports.UserCancelledError = void 0;
4
4
  class UserCancelledError extends Error {
5
- constructor(message = 'User backed out and cancelled navigation flow') {
5
+ constructor(message = "User backed out and cancelled navigation flow") {
6
6
  super(message);
7
7
  }
8
8
  }
@@ -1 +1,2 @@
1
- export declare function navigationFlow<T>(flow: Promise<T>): void;
1
+ export declare function navigationFlow<T>(flow: Promise<T> | (() => Promise<T>)): void;
2
+ export declare function navigationClickHandler<T>(flow: () => Promise<T>): () => void;
@@ -1,12 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.navigationFlow = void 0;
3
+ exports.navigationClickHandler = exports.navigationFlow = void 0;
4
4
  const resolver_1 = require("../navigation/resolver");
5
5
  function navigationFlow(flow) {
6
- flow.catch((err) => {
6
+ let promise;
7
+ if (flow instanceof Function) {
8
+ promise = flow();
9
+ }
10
+ if (flow instanceof Promise) {
11
+ promise = flow;
12
+ }
13
+ promise.catch((err) => {
7
14
  if (err instanceof resolver_1.UserCancelledError)
8
15
  return;
9
16
  console.error(err);
10
17
  });
11
18
  }
12
19
  exports.navigationFlow = navigationFlow;
20
+ function navigationClickHandler(flow) {
21
+ return () => navigationFlow(flow);
22
+ }
23
+ exports.navigationClickHandler = navigationClickHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/game-navigation-core",
3
- "version": "1.8.4",
3
+ "version": "1.9.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
package/src/game/game.ts CHANGED
@@ -46,7 +46,15 @@ export abstract class Game<ParamsType extends GameParams = GameParams> {
46
46
  }
47
47
 
48
48
  for (const plugin of this.plugins) {
49
- plugin.setup();
49
+ try {
50
+ plugin.setup();
51
+ } catch (err) {
52
+ console.error(
53
+ `Failed to setup ${plugin.key} plugin: ${err.message}`,
54
+ err,
55
+ );
56
+ throw err;
57
+ }
50
58
  }
51
59
 
52
60
  this.lastFrame = window.performance.now();
@@ -1,7 +1,9 @@
1
1
  import { Screen } from "../ui/screen";
2
2
 
3
3
  export class UserCancelledError extends Error {
4
- constructor(message: string = 'User backed out and cancelled navigation flow') {
4
+ constructor(
5
+ message: string = "User backed out and cancelled navigation flow",
6
+ ) {
5
7
  super(message);
6
8
  }
7
9
  }
@@ -15,7 +15,10 @@ export function getClientStorage(): Storage {
15
15
  }
16
16
  return storage;
17
17
  } catch (err) {
18
- console.error(`Failed to get ${label} (${err.message}), falling back`, err);
18
+ console.error(
19
+ `Failed to get ${label} (${err.message}), falling back`,
20
+ err,
21
+ );
19
22
  }
20
23
  }
21
24
  }
@@ -1,8 +1,22 @@
1
1
  import { UserCancelledError } from "../navigation/resolver";
2
2
 
3
- export function navigationFlow<T>(flow: Promise<T>) {
4
- flow.catch((err) => {
3
+ export function navigationFlow<T>(flow: Promise<T> | (() => Promise<T>)): void {
4
+ let promise: Promise<T>;
5
+
6
+ if (flow instanceof Function) {
7
+ promise = flow();
8
+ }
9
+
10
+ if (flow instanceof Promise) {
11
+ promise = flow;
12
+ }
13
+
14
+ promise.catch((err) => {
5
15
  if (err instanceof UserCancelledError) return;
6
16
  console.error(err);
7
17
  });
8
18
  }
19
+
20
+ export function navigationClickHandler<T>(flow: () => Promise<T>): () => void {
21
+ return () => navigationFlow(flow);
22
+ }