On Jul 3, 2008, at 7:56 AM, "artyom.shalkhakov" <artyom.s...@gmail.com
The formula is clear, thanks. But, I don't quite see why A and B are
behaviors (in the contract you wrote for your code). I'm going to
assume for a moment that they aren't behaviors but constant values.
Let me know if they are in fact behaviors.
Think carefully about 'ev'. When an event fires on 'ev', it signals
the start of your animation. You have to write splash_b so that it
works correctly for all events that fire on 'ev.'
That suggests something like this:
var elapsedEE = ev.lift_e(function(_) {
var ev = (new Date()).getTime();
var t = timer_e(dt); // note: event stream
t.lift_e(function(time) { if (time - ev >= d)
{ disableTimer(t); } }); // stop timer
return t.lift_e(function (t) {
return A+(B-A)*x((t-ev)/d); // function p, verbatim
}
});
Of course, you now have an event stream of event streams. However,
switch_e will flatten elapsedEE to the 'latest event stream':
var elapsedE = switch_e(elapsedEE);
You can now turn this into a behavior if you want:
elapsedE.startsWith(/* initial value */)
The type you've written for splash_b is perfectly valid. However, I
think it's clearly if you curry it, separating the constants
(x,A,B,d,dt) from the event that triggers
the animation (ev):
function splash_e(x,A,B,d,dt) {
return function(ev) {
return switch_e(ev.lift_e(function(_) {
var ev = (new Date()).getTime();
var t = timer_e(dt); // note: event stream
t.lift_e(function(time) { if (time - ev >= d)
{ disableTimer(t); } }); // stop timer
return t.lift_e(function (t) {
return A+(B-A)*x((t-ev)/d); // function p, verbatim
}
}));
};
};
Of course, if x,A,B,d,dt vary as well, you can always lift and switch
splash_e.
Arjun
I think Flapjax serves an entirely different purpose from these
libraries. Flapjax gives you a novel way to express the control flow
of your application with event streams, and allows values to "update
automatically" with behaviors. It lets you escape from writing
disconnected callbacks.
I'm not familiar with all the libraries you mentioned, but take
Scriptaculous/Prototypejs as a canonical example. They provide a
cross-browser interface to the DOM, in addition to various features
and enhancements to the DOM API. (Scriptaculous takes it quite a bit
further with animations, drag and drop, etc.) Flapjax does quite a
bit standardize the DOM interface, but it's not a replacement for
these libraries. I've found that Flapjax and Prototype/Scriptaculous
go rather well together.
Arjun