Trouble with Unify

69 views
Skip to first unread message

Dan Lidral-Porter

unread,
Aug 2, 2012, 7:20:31 AM8/2/12
to c2-...@googlegroups.com
Hey Gang,

I'm taking a stab at migrating the C2 examples to clojurescript, and I'm running into some problems when I try to generate some svg rects using `singult.unify`. I can make a rect just fine by sticking `[:rect.box {:x 0, :y 0, ...}]` directly in the hiccup vector that I hand to merge, but when I try to generate the same thing using unify, then singult.coffee.merge complains about an unexpectedly undefined value.

The actual unify invocation is:
```
(singult/unify (map-indexed vector data) (constantly [:rect.box {:x 0, :y 0, :width 20, :height 20}]))
```
I'm certain that there's not an issue with the first arg to unify, since I've verified that `data` is what I expect it to be, and in any case replacing that arg with `[1]` doesn't change anything. 

I've looked at the unify invocations in the ToDoMVC demo, and I can't tell what I'm doing wrong here. You can see the full context of this code here: https://github.com/aperiodic/c2-cljs-examples/blob/master/src/cljs/c2_cljs_examples/c2-cljs-examples.cljs.

Cheers,
-Dan
PGP.sig

Kevin Lynagh

unread,
Aug 2, 2012, 11:25:28 AM8/2/12
to c2-...@googlegroups.com
Dan,

You're running into an issue because unify isn't an only child---it's a sibling of the inline style element.
The contract of unify is basically, "make all of the children here look like these data through this template".
It's expected to be the only child, so the rendering code will only look for a unify in that position:


in your case, unify is the second child (behind the style element) so Singult doesn't notice that it's not a hiccup vector and blows up.

If you wrap the unify in a :g (svg group element) things work fine.

Also, I wouldn't really use Singult directly---you can still use bind! even if you aren't referencing any atoms within the body.
That will defer to Singult/merge! behind the scenes, but it has some extra convenience like allowing a CSS selector string as the first arg so you don't have to reach out to js/document.

Finally, the inline CSS strings in the examples are because the Clojure Hiccup library doesn't support maps---Singult does, so you can clean them up into {:style {:display "block"}} or whatever if you want.

best,

Kevin
--
Kevin Lynagh
Keming Labs
http://keminglabs.com
888.502.1042

Reply all
Reply to author
Forward
0 new messages