www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit ca7844d2c4499b6338e388f45539e09e9189cb41
parent 4248a7250b7ec37d1c48ef895a6f2a69f458f12f
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Thu, 22 Aug 2024 10:06:52 -0700

Fix addMode in Editor

Handlers ended up all using the same state.

Diffstat:
Mfiles/floorplans/floorplan/editor.js | 16++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js @@ -269,9 +269,17 @@ export class FloorplanEditor { } } + const getHandler = function(editor, handler) { + editor.mode_states[handler] = {} + return function(event) { + return handler(event, state, editor.mode_states[handler]) + } + } + // to pass use in another function let state = this this.modes[name].handlers = {} + this.mode_states[name] = {} for (let type in mode.handlers) { this.modes[name]["handlers"][type] = [] @@ -285,12 +293,8 @@ export class FloorplanEditor { for (let i in a) { console.debug("Create mode handler", name, type, a[i]) - let f = function(event) { - // NOTE: Maybe handler states should be local to each mode too? - return a[i](event, state, state["mode_states"][f]) - } - this["mode_states"][f] = {} - this["modes"][name]["handlers"][type].push(f) + this["modes"][name]["handlers"][type] + .push(getHandler(this, a[i])) } }