lib/vedeu/repositories/buffers.rb in vedeu-0.2.3 vs lib/vedeu/repositories/buffers.rb in vedeu-0.2.4

- old
+ new

@@ -47,88 +47,77 @@ # # If both the back and front buffers have no content, then the view is blank # and we should return nothing. # # @param name [String] - # @return [Hash] + # @return [Hash|NilClass] def latest(name) - if new_content?(name) - swap_buffers(name) - front_buffer(name) + swap_buffers(name) if new_content?(name) - elsif old_content?(name) - front_buffer(name) - - else - nil - - end + front_buffer(name) end private - # Swap the named back buffer into the front buffer of the same name. + # Swap the named back buffer into the front buffer of the same name. This is + # called when the back buffer has new content (perhaps as part of a + # refresh). It also resets the offsets (i.e. scroll position) # - # @api private # @param name [String] # @return [Hash] def swap_buffers(name) buffer = find(name) + Offsets.update({ name: name }) + storage.store(name, { front_buffer: buffer[:back_buffer], back_buffer: nil, }) end # Return a boolean indicating whether the named back buffer has new content. # - # @api private # @param name [String] # @return [Boolean] def new_content?(name) defined_value?(back_buffer(name)) end # Return a boolean indicating whether the named front buffer has content. # - # @api private # @param name [String] # @return [Boolean] - def old_content?(name) - defined_value?(front_buffer(name)) - end + # def old_content?(name) + # defined_value?(front_buffer(name)) + # end # Return the named back buffer. # - # @api private # @param name [String] # @return [Hash|Nil] def back_buffer(name) find(name)[:back_buffer] end # Return the named front buffer. # - # @api private # @param name [String] # @return [Hash|Nil] def front_buffer(name) find(name)[:front_buffer] end - # @api private # @return [Hash] def in_memory Hash.new do |hash, interface_name| hash[interface_name] = { front_buffer: nil, back_buffer: nil, } end end - # @api private # @param name [String] # @raise [BufferNotFound] When the entity cannot be found with this name. # @return [BufferNotFound] def not_found(name) fail BufferNotFound, "Cannot find buffer with this name: #{name.to_s}."