Bind onClick and onHold functions before wrapping them

This commit is contained in:
thepaperpilot 2022-03-13 15:55:14 -05:00
parent 8170f240c8
commit de4bb44e02
3 changed files with 6 additions and 6 deletions

View file

@ -87,7 +87,7 @@ export function createClickable<T extends ClickableOptions>(
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<T extends ClickableOptions>(
};
}
if (clickable.onHold) {
const onHold = clickable.onHold;
const onHold = clickable.onHold.bind(clickable);
clickable.onHold = function () {
if (unref(clickable.canClick)) {
onHold();

View file

@ -279,7 +279,7 @@ export function createGrid<T extends GridOptions>(
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<T extends GridOptions>(
};
}
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);

View file

@ -101,7 +101,7 @@ export function createTreeNode<T extends TreeNodeOptions>(
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<T extends TreeNodeOptions>(
};
}
if (treeNode.onHold) {
const onHold = treeNode.onHold;
const onHold = treeNode.onHold.bind(treeNode);
treeNode.onHold = function () {
if (unref(treeNode.canClick)) {
onHold();