Sha256: eb3fe51b9e8d7ead45437a82036095545eb63a7cc756d82c84f64b052eadb7fc

Contents?: true

Size: 1.4 KB

Versions: 46

Compression:

Stored size: 1.4 KB

Contents

#= require ./BackboneStore

Rev.registerComponent 'ModelPrepper',
  mixins: [Rev.Mixins.BackboneStore]

  getInitialState: ->
    state =
      model: null
      error: null

  componentWillMount: ->
    @fetch()

  get: ->
    @store.get @props.collection, @props.model

  fetch: ->
    @store.fetch @props.collection, @props.model, @onFetchComplete

  onFetchComplete: ->
    if model = @get()
      @setState
        model: model
    else
      @setState
        error: true

  render: ->
    if @state.model?
      @success()
    else if @state.error?
      @error()
    else
      @wait()

  success: ->
    if @props.onSuccess? then @props.onSuccess @state.model, this else @props.children

  error: ->
    if @props.onError? then @props.onError(@retry) else null

  wait: ->
    if @props.onWait? then @props.onWait() else null

  retry: ->
    @setState
      error: null

  # bindModelChanges: (model) ->
  #   # console.log "bind", model
  #   model.on 'add change remove', @forceUpdate.bind(this, null), this
  #
  # unbindModelChanges: (model) ->
  #   # console.log "unbind", model
  #   model.off null, null, this
  #
  # componentWillMount: ->
  #   @bindModelChanges @state.model if @state.model?
  #
  # componentWillUpdate: (props, state) ->
  #   if state.model? and not @state.model?
  #     @bindModelChanges state.model
  #
  # componentWillUnmount: ->
  #   @unbindModelChanges @state.model if @state.model?

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
revelry_core-0.1.12.6 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.12.5 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.12.4 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.12.3 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.12.2 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.12.0 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.11.6 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.11.5 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.11.2 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.11.1 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.11.0 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.7 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.6 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.5 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.4 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.3 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.2 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.1 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.10.0 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx
revelry_core-0.1.9.2 app/assets/javascripts/revelry/data/ModelPrepper.js.cjsx