rx/presenters

View on GitHub
app/demo/events/actions/last_response.pom

Summary

Maintainability
Test Coverage
Voom::Presenters.define(:last_response_action) do
  helpers Demo::Helpers::IndentedGrid
  attach :top_nav
  attach :events_drawer

  indented_grid do
    heading 'Last Response'
    body 'You can access the last response and forward its data to a snackbar or posts|updates|deletes|replaces|loads.'
    title 'Posts'
    button 'quote' do
      event :click do
        posts '_echo_', {quote: 'Compromise is the shared hypotenuse of the conjoined triangles of success.'}
        posts '_echo_', echo: {quote: last_response.quote}, headers: {'X-Custom'=>'Boom!'}
        snackbar last_response.echo.quote
      end
    end

    title 'Replaces'
    button 'replaces' do
      event :click do
        posts '_echo_', {quote: 'Compromise is the shared hypotenuse of the conjoined triangles of success.'}
        replaces :replace_me, :replace_text, text: last_response.quote
      end
    end
    attach :replace_text

    blank
    title "Loads another presesnter"
    text "Will reload this page passing a value from the last response of another action"
    text "Quote from last response: {c:blue}#{context.fetch(:quote, nil)}{/c}" unless context.fetch(:quote, nil).nil?
    button 'Reloads this page' do
      event :click do
        posts '_echo_', {quote: 'Compromise is the shared hypotenuse of the conjoined triangles of success.'}
        loads :last_response_action, reloaded: true, quote: last_response.quote
      end
    end
    heading context['reloaded'] ? "Reloaded" : 'Loaded'
  end
  attach :code, file: __FILE__
end