How can I use default sammy.js template plugin to interpolate on custom events?

206 views
Skip to first unread message

Lambder

unread,
Jan 25, 2011, 5:24:29 AM1/25/11
to Sammy.js
Hi All,


I got some custom events in my sammy app which are not part of
sammy event system. I'd like to avoid double inclusion of
Handlebars.js or to modify Sammy.Hanlebars to make Hanlebars object
available in the global scope. Ideally I'd like to have the access to
the underlying default templating object so i could use it without
EventContext. How can I do it? The only workaroud for this so far i
found is to delegate all my custom events (by triggering) to the
sammy.js events which give access to EventContext and in turn to
templating mechanism. Can I access templating objects without sammy.js
events or can i create my own EventContext ?

Cheers,
Lambder

Aaron Quint

unread,
Jan 25, 2011, 6:13:05 PM1/25/11
to sam...@googlegroups.com
The most common case that I've found for this is using events to pass
data back and forth. I personally like the encapsulation of the
templating in the app and not having it scattered everywhere. If you
do need to use handlebars outside of the application, you could _not_
include Sammy.Handlebars, just include the main handlebars and just
add the helper manually (if you look at the Sammy.Handlebars source,
the plugin itself is only around 5 lines of that whole file. Theres no
way to explicitly use an event context or a helper outside of the
context of the app as that would cause a number of problems with
certain methods/vars not being available when calling the helper.

--AQ

> --
> You received this message because you are subscribed to the Google Groups "Sammy.js" group.
> To post to this group, send email to sam...@googlegroups.com.
> To unsubscribe from this group, send email to sammyjs+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sammyjs?hl=en.
>
>

Lambder

unread,
Jan 26, 2011, 6:02:10 AM1/26/11
to Sammy.js
Hi Aaron,

Thanks for very clear and precise answer. Yes I was looking at
Sammy.Handlebars source and it makes sense to use standalone
Handlebars and wrap it into helper separately. I still have question
regarding this topic tho. Aa Oly describes it here (http://
groups.google.com/group/sammyjs/browse_thread/thread/
7caa6456a907197/580d1d39a9063074?lnk=gst&q=template#580d1d39a9063074)
it is easy to capture the EventContext during 'run' event, capture it
into closure or store in commonly visible variable by the functions
which need access to the EventContext (I don't dare call it
global ;) ) and use templating by utilizing that captured
EventContext. The question is wheather it is a good practice or using
this leak can do harm an app later on ?

--
Cheers,
Daaniel

Aaron Quint

unread,
Jan 28, 2011, 12:07:58 PM1/28/11
to sam...@googlegroups.com
Using the event context in 'run' is still considered good practice. If
you're binding a lot of events in there it might make sense to convert
some of them to helpers or Sammy events.
--AQ
Reply all
Reply to author
Forward
0 new messages