Sha256: aa10106f9481673cb45917c2fac4057572940d9c6b53abf887d6f449e159f5fe

Contents?: true

Size: 838 Bytes

Versions: 43

Compression:

Stored size: 838 Bytes

Contents

class ReactiveTemplate
  include Events
  
  def initialize(context, template_path)
    # puts "New Reactive Template: #{context.inspect} - #{template_path.inspect}"
    @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

43 entries across 43 versions & 1 rubygems

Version Path
volt-0.5.18 lib/volt/page/reactive_template.rb
volt-0.5.17 lib/volt/page/reactive_template.rb
volt-0.5.16 lib/volt/page/reactive_template.rb
volt-0.5.15 lib/volt/page/reactive_template.rb
volt-0.5.14 lib/volt/page/reactive_template.rb
volt-0.5.13 lib/volt/page/reactive_template.rb
volt-0.5.12 lib/volt/page/reactive_template.rb
volt-0.5.11 lib/volt/page/reactive_template.rb
volt-0.5.10 lib/volt/page/reactive_template.rb
volt-0.5.9 lib/volt/page/reactive_template.rb
volt-0.5.8 lib/volt/page/reactive_template.rb
volt-0.5.7 lib/volt/page/reactive_template.rb
volt-0.5.6 lib/volt/page/reactive_template.rb
volt-0.5.4 lib/volt/page/reactive_template.rb
volt-0.5.3 lib/volt/page/reactive_template.rb
volt-0.5.2 lib/volt/page/reactive_template.rb
volt-0.5.1 lib/volt/page/reactive_template.rb
volt-0.5.0 lib/volt/page/reactive_template.rb
volt-0.4.18 lib/volt/page/reactive_template.rb
volt-0.4.17 lib/volt/page/reactive_template.rb