plumatic / dommy

A tiny ClojureScript DOM manipulation and event library
759 stars 74 forks source link

deftemplate #17

Closed dubiousdavid closed 11 years ago

dubiousdavid commented 11 years ago

I'm wondering if deftemplate should explicitly reference the non-compiled version of node, and a sibling macro created defctemplate that explicitly references the compiled version of node. Perhaps these two macros could be put in a separate file? Right now you can't use deftemplate with the compiled and non-compiled versions of node, which seems like a shortcoming.

dubiousdavid commented 11 years ago

It would be nice to have defnode and defcnode as well in that file.

dubiousdavid commented 11 years ago

This should work:

(defmacro deftempl [name args node-form]
  `(defn ~name ~args
    (dommy.template/node ~node-form)))

(defmacro defctempl [name args node-form]
  `(defn ~name ~args
    (dommy.template-compile/node ~node-form)))

(defmacro defnode [name node-form]
  `(def ~name
     (dommy.template/node ~node-form)))

(defmacro defcnode [name node-form]
  `(def ~name
     (dommy.template-compile/node ~node-form)))
aria42 commented 11 years ago

Why would you want to use deftemplate with the non-compiled (runtime) templating? Why would you not take the policy of compile as much of what you can that deftemplate does?

dubiousdavid commented 11 years ago

The convenience of the macro is useful for when you can use the compiled version of node, but also when you cannot. My understanding is that the compiled version cannot be used when you need looping, which is the largest case for me, since I'm doing 100% client-side templating.

On Mar 22, 2013, at 2:35 PM, Aria Haghighi notifications@github.com wrote:

Why would you want to use deftemplate with the non-compiled (runtime) templating? Why would you not take the policy of compile as much of what you can that deftemplate does?

— Reply to this email directly or view it on GitHub.

aria42 commented 11 years ago

No. deftemplate should always work and fall back to runtime when it can no longer compile stuff (when you stop using literals); take a look the code and see where it calls the runtime when it no longer can parse. So deftemplate should always work regardless. Are you seeing a case where it's not.

On Fri, Mar 22, 2013 at 11:39 AM, David Sargeant notifications@github.comwrote:

The convenience of the macro is useful for when you can use the compiled version of node, but also when you cannot. My understanding is that the compiled version cannot be used when you need looping, which is the largest case for me, since I'm doing 100% client-side templating.

On Mar 22, 2013, at 2:35 PM, Aria Haghighi notifications@github.com wrote:

Why would you want to use deftemplate with the non-compiled (runtime) templating? Why would you not take the policy of compile as much of what you can that deftemplate does?

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHubhttps://github.com/Prismatic/dommy/issues/17#issuecomment-15314279 .

website: http://aria42.com

dubiousdavid commented 11 years ago

I'm not sure I fully understand what you are saying. The bottom line I believe is that the macro does not reference a specific version of node, and is not fully qualified, so the ambiguity is a problem if you want to use both versions of node.

On Mar 22, 2013, at 2:50 PM, Aria Haghighi notifications@github.com wrote:

No. deftemplate should always work and fall back to runtime when it can no longer compile stuff (when you stop using literals); take a look the code and see where it calls the runtime when it no longer can parse. So deftemplate should always work regardless. Are you seeing a case where it's not.

On Fri, Mar 22, 2013 at 11:39 AM, David Sargeant notifications@github.comwrote:

The convenience of the macro is useful for when you can use the compiled version of node, but also when you cannot. My understanding is that the compiled version cannot be used when you need looping, which is the largest case for me, since I'm doing 100% client-side templating.

On Mar 22, 2013, at 2:35 PM, Aria Haghighi notifications@github.com wrote:

Why would you want to use deftemplate with the non-compiled (runtime) templating? Why would you not take the policy of compile as much of what you can that deftemplate does?

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHubhttps://github.com/Prismatic/dommy/issues/17#issuecomment-15314279 .

website: http://aria42.com — Reply to this email directly or view it on GitHub.

aria42 commented 11 years ago

But why would you want to use both versions since the macro-variant will fallback to the runtime node (dommy.core/node) when the expression isn't compile-time parseable. Why wouldn't you prefer macro-compile when possible?

dubiousdavid commented 11 years ago

I didn't know that it worked that way. That sounds like a good solution as far as I understand things.

On Mar 24, 2013, at 5:54 PM, Aria Haghighi notifications@github.com wrote:

But why would you want to use both versions since the macro-variant will fallback to the runtime node (dommy.core/node) when the expression isn't compile-time parseable. Why wouldn't you prefer macro-compile when possible?

— Reply to this email directly or view it on GitHub.