-1

Update I think I might have it figured out. I was using an old bacon.js version, which might have been part of the problem. I'll update later as I figure out if I have it. Here's the partially working version: http://cdpn.io/yfxDA

I'm trying to call a function every time an element loses focus (an input but in the below example I'm using a div).

This is what I tried:

var $on = $('div')
$on.asEventStream('focusout').subscribe(alert('no!'))

and

var $on = $('div')
$on.asEventStream('focusout').onValue(alert('no!'))

They both work the first time but then stop working. Is there a way to get this to work?

Eventually I would like to merge focusin/focusout and perform a side-effect.

Jon49
  • 4,444
  • 4
  • 36
  • 73
  • You may not have realised, but your alerts are being executed on the parse phase. I mean, onValue takes a function definition: onValue(function(){alert('no!');}); – TurboHz May 02 '14 at 18:21

2 Answers2

0

It looks like I just needed the most up to date version of the software. Here's what the code looks like now:

var $on = $('div')
var $h = $('div input')
var d = 'contains'

$h.val(d)
var f = function(arg){
  return ($h.val() === d) ? '' : d
} 

$on.asEventStream('focusout').merge($on.asEventStream('focusin')).toProperty().assign($h, 'val', f)
Jon49
  • 4,444
  • 4
  • 36
  • 73
0

I works just fine with the latest version: http://codepen.io/anon/pen/xLHyq

TurboHz
  • 2,146
  • 2
  • 16
  • 14
  • I -1 the question because is not useful anymore. Also check out my comment on the question itself. Your sample code has a silly mistake that adds to your confusion analysing the issue. – TurboHz May 03 '14 at 08:10