@momo2555/koppeliajs 0.0.114 → 0.0.116

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.
@@ -68,7 +68,7 @@ export class Koppelia {
68
68
  this._console.onReady(() => {
69
69
  let type = get(routeType);
70
70
  if (type == "controller") {
71
- this._state.setState(defaultState); // set the state
71
+ this._state.setState(defaultState, true); // set the state
72
72
  this._stage.initStages(stages); // init the list of stages
73
73
  }
74
74
  });
@@ -8,6 +8,7 @@ export declare class State {
8
8
  private _console;
9
9
  private _access;
10
10
  private _previousStateValue;
11
+ private _forceState;
11
12
  constructor(console: Console, defaultState?: AnyState);
12
13
  get state(): Writable<AnyState>;
13
14
  /**
@@ -18,7 +19,7 @@ export declare class State {
18
19
  * Force change the state with a new one
19
20
  * @param newState
20
21
  */
21
- setState(newState: AnyState): void;
22
+ setState(newState: AnyState, force?: boolean): void;
22
23
  /**
23
24
  * Marge a new update to the last one
24
25
  * @param stateUpdate
@@ -6,10 +6,12 @@ export class State {
6
6
  _console;
7
7
  _access = true;
8
8
  _previousStateValue = {};
9
+ _forceState;
9
10
  constructor(console, defaultState = {}) {
10
11
  this._access = false;
11
12
  this._globalState = writable(defaultState);
12
13
  this._console = console;
14
+ this._forceState = false; // force the state without update
13
15
  this._initEvents();
14
16
  this._access = true;
15
17
  }
@@ -31,7 +33,8 @@ export class State {
31
33
  * Force change the state with a new one
32
34
  * @param newState
33
35
  */
34
- setState(newState) {
36
+ setState(newState, force = false) {
37
+ this._forceState = force;
35
38
  this._globalState.set(newState);
36
39
  }
37
40
  /**
@@ -82,7 +85,8 @@ export class State {
82
85
  let req = new Message();
83
86
  req.setRequest("changeState");
84
87
  req.addParam("state", update);
85
- req.addParam("update", true);
88
+ req.addParam("update", !this._forceState);
89
+ this._forceState = false;
86
90
  this._console.sendMessage(req);
87
91
  });
88
92
  }
@@ -97,13 +101,13 @@ export class State {
97
101
  let state = get(this._globalState);
98
102
  for (let entry in receivedState) {
99
103
  state[entry] = receivedState[entry];
104
+ this._previousStateValue[entry] = structuredClone(receivedState[entry]);
100
105
  }
101
106
  this._globalState.set(state);
102
107
  }
103
108
  else {
104
109
  this._globalState.set(receivedState);
105
110
  }
106
- this._previousStateValue = get(this._globalState);
107
111
  this._access = true;
108
112
  }
109
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo2555/koppeliajs",
3
- "version": "0.0.114",
3
+ "version": "0.0.116",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",