Sha256: 50e2b82a9308f46813b354a40cbbdcbaa5f6c0e171c0d858cfb188a510d21868

Contents?: true

Size: 723 Bytes

Versions: 3

Compression:

Stored size: 723 Bytes

Contents

this.LiveRecord.plugins.LiveDOM || (this.LiveRecord.plugins.LiveDOM = {});

LiveRecord.plugins.LiveDOM.applyToModel = (Model, pluginValue) ->
  return if pluginValue != true

  # DOM callbacks

  Model._updateDomCallback = ->
    $updateableElements = $('[data-live-record-update-from]')

    for key, value of this.attributes
      $updateableElements.filter('[data-live-record-update-from="' + Model.modelName + '-' + this.id() + '-' + key + '"]').text(this[key]())

  Model._destroyDomCallback = ->
    $('[data-live-record-destroy-from="' + Model.modelName + '-' + this.id() + '"]').remove()

  Model.addCallback('after:update', Model._updateDomCallback)
  Model.addCallback('after:destroy', Model._destroyDomCallback)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
live_record-0.0.3 app/assets/javascripts/live_record/plugins/live_dom.coffee
live_record-0.0.2 app/assets/javascripts/live_record/plugins/live_dom.coffee
live_record-0.0.1 app/assets/javascripts/live_record/plugins/live_dom.coffee