Sha256: cff1b57576939d7cb348f52352048489b5d52457e50270fc0bb4e4e92a87db3e

Contents?: true

Size: 756 Bytes

Versions: 6

Compression:

Stored size: 756 Bytes

Contents

class ReactiveTemplate
  include Events
  
  def initialize(context, template_path)
    @template_path = template_path
    @target = AttributeTarget.new
    @template = TemplateRenderer.new(@target, context, "main", template_path)
  end
  
  def event_added(event, scope_provider, first)
    if first && !@template_listener
      @template_listener = @target.on('changed') { update }
    end
  end
  
  def event_removed(event, last)
    if last && @template_listener
      @template_listener.remove
      @template_listener = nil
    end
  end
  
  # Render the template and get the current value
  def cur
    @target.to_html
  end
  
  # TODO: improve
  def skip_current_queue_flush
    true
  end
  
  
  def update
    trigger!('changed')
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
volt-0.3.0 lib/volt/templates/reactive_template.rb
volt-0.2.9 lib/volt/templates/reactive_template.rb
volt-0.2.7 lib/volt/templates/reactive_template.rb
volt-0.2.5 lib/volt/templates/reactive_template.rb
volt-0.2.4 lib/volt/templates/reactive_template.rb
volt-0.2.3 lib/volt/templates/reactive_template.rb