dalgard / meteor-viewmodel

Minimalist VM for Meteor
24 stars 2 forks source link

Init function #7

Closed zimt28 closed 8 years ago

zimt28 commented 8 years ago

Do you think it could make sense to add an init function next to get and set? I just wrote a binding, which needs to hide/ show an element initially. I have a working solution, but I think that putting the code into an init function would be nicer:

ViewModel.addBinding 'slide', ->
  firstRun = true

  set: ($elem, new_value, args, kwhash) ->
    if firstRun
      if not new_value and $elem.is ':visible'
        console.warn 'To avoid flickering you should use CSS to hide the element', $elem.get(0), 'initially'
        $elem.hide()
      firstRun = false

    if new_value
      $elem.slideDown()
    else
      $elem.slideUp()
dalgard commented 8 years ago

I agree, I'm adding it in the next version.

dalgard commented 8 years ago

Added in 0.6.0.