lib/volt/page/bindings/each_binding.rb
# When a changed event happens, we update to the new size.
When a changed event happens, we update to the new size.
When a changed event happens we update to the new size .
def reload
      begin
        value = @context.instance_eval(&@getter)
      rescue => e
        Volt.logger.error("EachBinding Error: #{e.inspect}")
        value = []
      end
      Computation.run_without_tracking do
        values = current_values(value)
        @value = values
        @added_listener.remove if @added_listener
        @removed_listener.remove if @removed_listener
        if @value.respond_to?(:on)
          @added_listener   = @value.on('added') { |position| item_added(position) }
          @removed_listener = @value.on('removed') { |position| item_removed(position) }
        end
        templates_size = @templates.size
        values_size    = values.size
        (templates_size - 1).downto(0) do |index|
          item_removed(index)
        end
        0.upto(values_size - 1) do |index|
          item_added(index)
        end
      end
    end
def reload begin value = @context . instance_eval ( & @getter ) rescue => e Volt . logger . error ( "EachBinding Error: #{e.inspect}" ) value = [ ] end Computation . run_without_tracking do values = current_values ( value ) @value = values @added_listener . remove if @added_listener @removed_listener . remove if @removed_listener if @value . respond_to? ( :on ) @added_listener = @value . on ( 'added' ) { | position | item_added ( position ) } @removed_listener = @value . on ( 'removed' ) { | position | item_removed ( position ) } end templates_size = @templates . size values_size = values . size ( templates_size - 1 ) . downto ( 0 ) do | index | item_removed ( index ) end 0 . upto ( values_size - 1 ) do | index | item_added ( index ) end end end
When a changed event happens, we update to the new size.
When a changed event happens we update to the new size .
# Since we're checking things like size, we don't want this to be re-triggered on a # size change, so we run without tracking. # puts "RELOAD:-------------- #{value.inspect}" # Adjust to the new size # Start over, re-create all nodes