When dealing with specific events bound to a single dom element, I'd like a way to be able to make it apparent that the element in question has events...without looking at the javascript (along with removing double referencing).
For example, let's take this simple template:
<script type="text/template" id="template-page">
<button id="do-something">click me</button>
</script>
I could use a symbol that was not being used by any of the template parsers in question (in my case, I'm using Play!, so @
is out), and make it apparent to a developer that the button is bound to an event (I'm actually not sure if this works, but you get the gist):
<script type="text/template" id="template-page">
<button id="~do-something">click me</button>
</script>
While using the ~
to represent an element bound to an event would work, it is still referenced twice in the app - once in the template above, and once in the view:
class window.Page extends Backbone.Marionette.Layout
template: '#template-page'
events:
'click button#~do-something': 'doSomething'
Is there a better way to do this? It's very easy for things to go wrong, and to accidentally make a change to the html without understanding the consequences (especially if naming patterns evolve, etc). I can think of one way, but am having a little bit of trouble.
It would be cool to specify a variable in the view, perhaps.
class window.Page extends Backbone.Marionette.Layout
template: '#template-page'
@doSomethingButton: 'button#do-something'
events:
'click #{doSomethingButton}: 'doSomething'
I can't seem to get this information to a template, though. I saw something like so: How to pass additional variables in to underscores templates, but no dice. Ideally, it would look like this:
<script type="text/template" id="template-page">
<button id="<%= Page.doSomethingButton %>">click me</button>
</script>
And then I'd have the visibility I want! Here's what I've been trying: http://jsfiddle.net/franklovecchio/FkNwG/248/