Using singult Unify with coffeescript

43 views
Skip to first unread message

Dimitris Stefanidis

unread,
Sep 25, 2012, 8:21:03 AM9/25/12
to c2-...@googlegroups.com
Hi All, 

I have been fruitlessly trying to use singult.Unify with a coffeescript application.

I am using the minified build of the singult lib found here https://github.com/downloads/lynaghk/singult/singult.min.js

The following code

itemFn = (item) -> ["div", item]
singult.Unify([1,2,3,4], itemFn)

returns undefined. 

Stepping into the code shows that singult.Unify just performs a few assignments into this
which is window.singult and it returns the result of the last assignment which is "return this.g = f".
f is the exit function which is optional along with the enter update and key_fn.
This is the minified version of the singult.Unify function 

function y(a, b, c, e, d, f) {
    this.data = a;
    this.b = b;
    this.d = c;
    this.a = e;
    this.update = d;
    return this.g = f
}

I see that the Unify function in the coffee source takes an extra parameter (force_update_p) and ends with
"return this" and not "return this.g = f"

Calling

itemFn = (item) -> ["div", item]
singult.render(["div", singult.Unify([1,2,3,4], itemFn)])

throws cannot read property 0 of undefined while calling the following function

explode_p = function(v) {
  return v[0] === ":*:";
};

Any insights would be greatly appreciated cause I am pretty much stuck. 

Also I havent researched this alot but is it possible to escape-html while creating content nodes ?

Thanks,
Dimitris









Kevin Lynagh

unread,
Sep 27, 2012, 11:09:02 AM9/27/12
to c2-...@googlegroups.com
Dimitris,

Congratulations!
You're the first user I'm aware of that's trying to use the JavaScript build of Singult = )

I haven't been syncing the JS build on the github page.
Have you tried grabbing the latest master and compiling it yourself?
You should be able to run the `make_js.sh` script in the toplevel (you'll need CoffeeScript installed).
Also I havent researched this alot but is it possible to escape-html while creating content nodes ?

Text strings are rendered as text nodes, not innerHTML or anything.
Is that what you mean?

Dimitris Stefanidis

unread,
Sep 27, 2012, 1:26:42 PM9/27/12
to c2-...@googlegroups.com
Hi Kevin,

Thanks for the reply.

>> You should be able to run the `make_js.sh` script in the toplevel (you'll need CoffeeScript installed).
I had tried compiling on two different macs before posting but got ERROR - Cannot read: vendor/closure/closure/goog/base.js both times. 
Any ideas about this ?

>> Text strings are rendered as text nodes, not innerHTML or anything.
I meant the oposite of what I wrote. I have some text returned from the server in the form "<p>some content</p><p>something else</p>"
I would like for the paragraph nodes to be created but as I saw this 

else if string_p m #TODO: how to handle raw html?
return document.createTextNode m

in the code I guess I cant do it right now. Right ?

Kevin Lynagh

unread,
Sep 27, 2012, 1:34:24 PM9/27/12
to c2-...@googlegroups.com
>> You should be able to run the `make_js.sh` script in the toplevel (you'll need CoffeeScript installed).
I had tried compiling on two different macs before posting but got ERROR - Cannot read: vendor/closure/closure/goog/base.js both times. 
Any ideas about this ?

Sounds like you need to initialize the git submodule that contains the closure library:

    git submodule update --init
 

>> Text strings are rendered as text nodes, not innerHTML or anything.
I meant the oposite of what I wrote. I have some text returned from the server in the form "<p>some content</p><p>something else</p>"
I would like for the paragraph nodes to be created but as I saw this 

else if string_p m #TODO: how to handle raw html?
return document.createTextNode m

in the code I guess I cant do it right now. Right ?

Yep.
There is an open issue on the github repository I believe.
I'm not sure what the nicest way to add this kind of feature would be.
Raw HTML be added as a special object in the same way that "unify" is a special datatype for Hiccup, but I'd need to give it some more thought.
Reply all
Reply to author
Forward
0 new messages