JavaScript Handling double clicks AND single clicks gracefully with FRP and Bacon.js

I'm trying to find the most graceful way to distinguish between single and double clicks in Bacon.js, but I feel like I'm not completely grasping how this works. The following works for detecting a double-click, but I'm a bit stumped as to how I would specify different behavior (i.e., a different callback function) elegantly for a single-click event.

  clicked = Bacon.fromEventTarget(document, "click")
  clicked.bufferWithTimeOrCount(300, 2)
          .filter((x) -> x.length is 2)
          .onValue (x) ->
            console.log "double clicked: ", x
Answer:1

You would probably be better off using "dblclick" for that separately - you will avoid the need to specify your own timing interval for what counts as a single-click vs. a double-click. On the other hand, with the straightforward use of "click"/"dblclick" both events will be fired in case of a double-click.

If you prefer specifying your own logic, then it would probably be as doing a different filter on the length:

clicked = Bacon.fromEventTarget(document, "click")
buffered = clicked.bufferWithTimeOrCount(300, 2)
buffered.filter((x) -> x.length is 2)
        .onValue (x) ->
          console.log "double clicked: ", x            
buffered.filter((x) -> x.length is 1)
        .onValue (x) ->
          console.log "single clicked: ", x

Also, perhaps it could be made more elegant by using flatmap to create a single stream of clicks:

clicks = clicked.bufferWithTime(300)
   .flatMap((x) ->
     if (x.length < 2) 
       Bacon.once("single")
     else 
       Bacon.once("double")
   )

Then you can do your onValue and compare the values.

By doing bufferWithTime (without count) you will classify a triple-click as a double-click as well, but it depends on what your desired behaviour is.

Answer:2

I have a input that have type like this: <input class="emailSend" name="emailSend" type="hidden"> Then I have a multiple select option like this <div class="controls"> <select ...

I have a input that have type like this: <input class="emailSend" name="emailSend" type="hidden"> Then I have a multiple select option like this <div class="controls"> <select ...

  1. fill input type file javascript
  2. fill input type date
  3. fill input type file
  4. auto fill input type file
  5. pre fill input type date
  6. jquery fill input type file
  7. jquery fill input type text
  8. jquery fill input type date
  9. js fill input type file

The cell content selection works successfully for a numeric text box (internally handled as a Kendo NumericTextBox control) but for some reason, it doesn't work with a plain textbox column. Attached ...

The cell content selection works successfully for a numeric text box (internally handled as a Kendo NumericTextBox control) but for some reason, it doesn't work with a plain textbox column. Attached ...

  1. kendo ui grid select row
  2. kendo ui grid select all rows
  3. kendo ui grid select row programmatically
  4. kendo ui grid select row event
  5. kendo ui grid select column
  6. kendo ui grid select all checkbox
  7. kendo ui grid select single row
  8. kendo ui grid select cell programmatically
  9. kendo ui grid select row by index
  10. kendo ui grid select first row by default
  11. kendo ui grid select row on button click
  12. kendo ui grid select row after refresh
  13. kendo ui grid select row angular
  14. kendo ui grid select
  15. kendo ui grid select all
  16. kendo ui grid select event
  17. kendo ui grid select multiple rows
  18. kendo ui grid select row by id
  19. kendo ui grid select first row
  20. kendo ui grid select row checkbox

I want to have two optional parts in my regex - either of them can be found in matching string, and also both of them can at the same time. Both of those optional parts consist of a wildcard (I wrote ...

I want to have two optional parts in my regex - either of them can be found in matching string, and also both of them can at the same time. Both of those optional parts consist of a wildcard (I wrote ...

In the parent html page , when I click a link fancybox dialog opens up and I load a laravel php view page in that fancybox. When I press 'login with twitter' button in fancybox dialog, then I want ...

In the parent html page , when I click a link fancybox dialog opens up and I load a laravel php view page in that fancybox. When I press 'login with twitter' button in fancybox dialog, then I want ...