Bi-Directional Lifting

61 views
Skip to first unread message

Jay Shepherd

unread,
Nov 14, 2011, 10:18:43 PM11/14/11
to Flapjax
Hey Guys
Im currently working on my widget system and am experimenting with bi-
directional behaviours. So first ide like to know is this something
that anyone else has thought about? Or possibly planning to implement
in flapjax?

I think it would be great because, as data can flow from the database
to the dom it could also flow from the dom to the database. Rather
than the widgets at the bottom of the tree knowing about the data/
behaviours at the top and updating the systems state at the top. You
could have the widgets isolated and only knowing about thier direct
behaviours, so they react to the behaviour to render, and set
(sendEvent) the behaviour to update. That send event then runs up the
tree in the opposite direction.

Does that make sense?

Basically i would to add an inverse-able liftB so that data can flow
both ways and this would achieve an encapsulation of sorts.

Here is my first rough experiement, my next attempt will aim to work
like liftB does rather than wrapping it up.

function liftBI(f, argsF, fI){
var event = receiverE();
event.mapE(fI);
var sendEvent=function(data){
event.sendEvent(data);
}
argsF.unshift(f);
var behaviour = liftB.apply(this, argsF);
}

Basically im just curious what people think about the idea, if its
already been thought about, and if anyone has any tips as this works
but isnt very pretty :D

Thanks!

Aran Donohue

unread,
Nov 15, 2011, 1:14:48 AM11/15/11
to fla...@googlegroups.com
Hey Jay,

I've thought about this stuff a little bit :) You might want to look into the research on "lenses" to see if that matches up with what you're trying to do.

Do you have a concrete problem you're trying to solve? What obstacles are you trying to overcome?

Aran

Shriram Krishnamurthi

unread,
Nov 15, 2011, 7:58:21 AM11/15/11
to fla...@googlegroups.com, Michael Greenberg
Hi Jay,

You should look at Michael Greenberg's undergrad thesis:

http://www.cs.brown.edu/research/pubs/theses/ugrad/2007/greenberg.pdf

"Widespread use of HTML [W3Cb], JavaScript, and the DOM [W3Ca] has led
to sub-optimal ‘best practices’. We apply the bidirectional
programming formalism of lenses [FGM+05] to define user interfaces in
JavaScript that are declarative, composable, clear, and concise — in
half the code. Additionally, we define two new bidirectional combinator
over lists, order and list map."

which was done in the context of Flapjax ("This work grew out of
frustrations with the need to use the DOM as an ad hoc data model when
programming even the simplest Flapjax programs with remote updates").
You may be able to get his code from him and use it as a starting
point.

Shriram

Michael Greenberg

unread,
Nov 15, 2011, 9:22:32 AM11/15/11
to Shriram Krishnamurthi, fla...@googlegroups.com
Hi,

My thesis work remains on-line at
<http://www.cis.upenn.edu/~mgree/ugrad/lenses/>, and I'd be happy to
answer any questions you have.

Also, a great deal of progress has been made on lenses, mostly by
Daniel Wagner. I think his latest work, "Edit Lenses", would sit
excellently atop JS/Flapjax.

Cheers,
Michael

Michael Bradley, Jr.

unread,
Nov 15, 2011, 8:47:38 PM11/15/11
to fla...@googlegroups.com, Shriram Krishnamurthi
Michael, thanks for the tip re: Wagner and "edit lenses" -- couldn't have come at a better time!

Jay Shepherd

unread,
Dec 21, 2011, 6:01:58 PM12/21/11
to Flapjax
Thanks Guys,
Both of those papers where a good read.
Ive put together a simple solution to the problem for now but its a
bit messy under the hood.
From the outside you just call liftB with two functions instead of
one.

If anyone wants to take a look at the code i can post it up once ive
cleaned it up a bit

On Nov 16, 2:47 pm, "Michael Bradley, Jr."
Reply all
Reply to author
Forward
0 new messages