Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created December 23, 2013 08:48
Show Gist options
  • Save mizchi/8093630 to your computer and use it in GitHub Desktop.
Save mizchi/8093630 to your computer and use it in GitHub Desktop.
API proposal: Simple angular like view model and backbone style events.
# initialize
Namari.setPrefix 'mz-'
Namari.registerDirective "text", (self, el, value) ->
$(el).text self[value]
Namari.registerDirective "html", (self, el, value) ->
el.innerHTML = self.get value
Namari.registerDirective "click", (self, el, value) ->
$(el).on 'click', self[value]
Namari.registerDirective "click-publish", (self, el, value) ->
$(el).on 'click', -> self.trigger value
# code
Namari.addTemplate 'status', """
<div class="status"
mz-container="status"
mz-values="name, money"
mz-require-functions="addMoney">
<span mz-text="name"></span>
<span mz-text="money"></span>
<button mz-click-publish="update">addMoney</span>
<button mz-click="addMoney">addMoney</span>
</div>
"""
class Status extends Namari.Stuff
templateName: 'status'
constructor: (name) ->
super
@name = name
addMoney: ->
@money += 1
status = new Status 'hoge'
status.on 'update', -> console.log 'update!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment