Time varying textnode

36 views
Skip to first unread message

ewen

unread,
Jan 10, 2013, 6:53:56 PM1/10/13
to fla...@googlegroups.com
Hello,

I am trying to create "time varying" textnodes using flapjax. I am able to create time-varying dom element using functions such as SPAN, P, DIV and so on, but the TEXT function does not seem to work with behaviours.
Did I miss a function to build such nodes?

I ended with a custom implementation but I wonder if it is the right way to do this:

var TEXT2 = function (textB){
        var elt = document.createTextNode();
        elt.nodeValue=textB.valueNow();

        textB.liftB(function(currentVal) {
                            elt.nodeValue = currentVal;
            });

        return elt;
    }

Thank you !

Ewen.

Arjun Guha

unread,
Jan 10, 2013, 7:51:34 PM1/10/13
to Flapjax
Hi Ewen,

Your function should work just fine. Or, use the Flapjax function TEXTB.

 We ought to rename that to just TEXT. That "B" suffix indicates that it consumes behaviors. It is a holdover from the first version of Flapjax, where all functions were suffixed B or E. 

Arjun

ewen

unread,
Jan 11, 2013, 3:18:23 PM1/11/13
to fla...@googlegroups.com
Hi Arjun,

Yes I noticed the TEXTB function but it returns a Behaviour and not a DOM element and thus can't be directly used by external DOM manipulation libraries.
I will keep using my implementation since it seems to work fine.

Thank you very much for your help :)

Ewen.

Arjun Guha

unread,
Jan 14, 2013, 2:08:46 AM1/14/13
to Flapjax
There is no good reason for TEXTB to return a behavior, is there? I think Flapjax should just return a constant text node like yours.

Arjun


Leo Meyerovich

unread,
Jan 14, 2013, 2:46:40 AM1/14/13
to fla...@googlegroups.com
Hi all,

The issue motivating a behavioral result rather than a raw DOM node for the DOM construction methods is that style changes may require reconstruction of the DOM node. 

Most style updates were handled destructively inlace (e.g., {color: myColorB}). However, if the style object was a behavior ( styleB ) and the set of properties changed, the object would be reconstructed to ensure correct handling of attributes that are no longer specified (e.g., styleB = {fontSize: 2} says nothing about color). A smarter version might be inplace by diffing the two objects and somehow inferring the default value, but that seems hard.

- Leo

Arjun Guha

unread,
Jan 14, 2013, 8:38:43 PM1/14/13
to Flapjax
Ah, I see! Yes, time-varying styles are quite complex.
Reply all
Reply to author
Forward
0 new messages