ManuelDeLeon / viewmodel

MVVM for Meteor
https://viewmodel.org
MIT License
205 stars 23 forks source link

Excessive nesting for declaring events in the code #240

Closed comerc closed 8 years ago

comerc commented 8 years ago

Vanilla Blaze:

Template.my.events
  'click #id': ->

VS ViewModel:

Template.my.viewmodel
  events:
    'click #id': ->

I want to suggest:

Template.my.viewmodel.events
  'click #id': ->

PS I know about binding events by function name, but ...

ManuelDeLeon commented 8 years ago

You can still use

Template.my.events
  'click #id': ->

with ViewModel

comerc commented 8 years ago

But I want to use "this" of ViewModel inside event handler.

Template.my.events
  'click #id': (e, t) ->
    t.viewmodel.myValue()

VS

Template.my.viewmodel.events
  'click #id': ->
    @myValue()
ManuelDeLeon commented 8 years ago

There is no way you'll convince me that

Template.example.viewmodel
  myValue: ''

Template.example.viewmodel.events
  'click #id': ->
    @myValue()

is somehow cleaner/easier/better than:

Template.example.viewmodel
  myValue: ''
  events:
    'click #id': ->
      @myValue()
comerc commented 8 years ago

OK. I may use:

Template.example.viewmodelEvents = 
  'click #id': ->
    @myValue()

Template.example.viewmodel
  myValue: ''
  events: Template.example.viewmodelEvents