From de4bb44e02786be35681b72c64075d8edd63bbd2 Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 13 Mar 2022 15:55:14 -0500 Subject: [PATCH] Bind onClick and onHold functions before wrapping them --- src/features/clickables/clickable.ts | 4 ++-- src/features/grids/grid.ts | 4 ++-- src/features/trees/tree.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features/clickables/clickable.ts b/src/features/clickables/clickable.ts index dfd4b08..3f1ba11 100644 --- a/src/features/clickables/clickable.ts +++ b/src/features/clickables/clickable.ts @@ -87,7 +87,7 @@ export function createClickable( processComputable(clickable as T, "display"); if (clickable.onClick) { - const onClick = clickable.onClick; + const onClick = clickable.onClick.bind(clickable); clickable.onClick = function () { if (unref(clickable.canClick)) { onClick(); @@ -95,7 +95,7 @@ export function createClickable( }; } if (clickable.onHold) { - const onHold = clickable.onHold; + const onHold = clickable.onHold.bind(clickable); clickable.onHold = function () { if (unref(clickable.canClick)) { onHold(); diff --git a/src/features/grids/grid.ts b/src/features/grids/grid.ts index 6a2254a..87f889a 100644 --- a/src/features/grids/grid.ts +++ b/src/features/grids/grid.ts @@ -279,7 +279,7 @@ export function createGrid( processComputable(grid as T, "getDisplay"); if (grid.onClick) { - const onClick = grid.onClick; + const onClick = grid.onClick.bind(grid); grid.onClick = function (id, state) { if (unref((grid as GenericGrid).cells[id].canClick)) { onClick(id, state); @@ -287,7 +287,7 @@ export function createGrid( }; } if (grid.onHold) { - const onHold = grid.onHold; + const onHold = grid.onHold.bind(grid); grid.onHold = function (id, state) { if (unref((grid as GenericGrid).cells[id].canClick)) { onHold(id, state); diff --git a/src/features/trees/tree.ts b/src/features/trees/tree.ts index cc3f69d..8490128 100644 --- a/src/features/trees/tree.ts +++ b/src/features/trees/tree.ts @@ -101,7 +101,7 @@ export function createTreeNode( processComputable(treeNode as T, "mark"); if (treeNode.onClick) { - const onClick = treeNode.onClick; + const onClick = treeNode.onClick.bind(treeNode); treeNode.onClick = function () { if (unref(treeNode.canClick)) { onClick(); @@ -109,7 +109,7 @@ export function createTreeNode( }; } if (treeNode.onHold) { - const onHold = treeNode.onHold; + const onHold = treeNode.onHold.bind(treeNode); treeNode.onHold = function () { if (unref(treeNode.canClick)) { onHold();