witheve / Eve

Better tools for thought

Home Page:http://witheve.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues with the click event

smarks159 opened this issue · comments

The following code demonstrates a few issues I experienced with the click event.

First, the click event fires for all mouse buttons, which was surprising, I would expect the click event to fire just for the left mouse button.

Second, the button attribute is not set on the click event so I can't check for click events where the left button is pressed.

I found a work around for this. You can use the mouse-down event instead of the click event and the button attribute is set. So in the below code if you change the click event to mouse-down event and add the line clickEvent.button=="left", then the code will work as expected.

import {Program} from "witheve";

let prog = new Program("Test Program");
prog.attach("ui");

prog.commit("test",({record,find})=>{
    return [
        record("ui/row","click_target",{text:"test1"}),
        record("ui/row","click_target",{text:"test2"}),
        record("ui/row",{children:[
            record("ui/row",{"text":"output:"}),
            record("ui/row","output")
        ]})
    ]
});

prog.commit("output text click",({record,find})=>{
    let clickTarget=find("click_target");
    let clickEvent=find("html/event/click",{element:clickTarget});      
    return[
        record("ui/row","output").remove("text").add("text",clickTarget.text)
    ]
});

prog.inputEAVs([
  [1, "tag", "turtle"]
]);

Hey @smarks159,

After some testing I've come up with a reasonably robust solution to the problem. You can track it's progress here: #836 It should land in master tomorrow, and will be released on npm next week.