lib/volt/repo_cache/collection.rb in volt-repo_cache-0.1.7 vs lib/volt/repo_cache/collection.rb in volt-repo_cache-0.1.8

- old
+ new

@@ -50,14 +50,18 @@ promises = [] unless read_only # models are removed from @marked_from_destruction as # they are flushed, so we need a copy of them to enumerate @marked_for_destruction.values.dup.each do |e| + # __debug __method__, __LINE__, "@marked_for_destruction calling #{e.class}:#{e.id}.flush!" promises << e.flush! + # __debug __method__, __LINE__, "@marked_for_destruction called #{e.class}:#{e.id}.flush!" end each do |e| + # __debug __method__, __LINE__, "each calling #{e.class}:#{e.id}.flush!" promises << e.flush! + # __debug __method__, __LINE__, "each called #{e.class}:#{e.id}.flush!" end end Promise.when(*promises) end @@ -112,18 +116,20 @@ if @marked_for_destruction[model.id] raise RuntimeError, "#{model} already in #{self.name} @marked_for_destruction" end @marked_for_destruction[model.id] = model __remove__(model, error_if_absent: true) + @cached_ids.delete(model.id) end # Called by RepoCache::Model#__destroy__. # Remove model from marked_for_destruction bucket. # Don't worry if we can't find it. def destroyed(model) - @cached_ids.delete(model.id) - @marked_for_destruction.delete(model.id) + # __debug __method__, __LINE__, "#{model.class}.id=#{model.id}" + result = @marked_for_destruction.delete(model.id) + # __debug __method__, __LINE__, "@marked_for_destruction.delete(#{model.id}) => #{result}" end # Collection is being notified (probably by super/self) # that a model has been added or removed. Pass # this on to associations. @@ -195,11 +201,11 @@ end unless model.class == model_class raise ArgumentError, "#{model} must be a #{model_class_name}" end if model.cached? - __debug __method__, __LINE__, "id=#{model.id} model.cached?=#{model.cached?}" + # __debug __method__, __LINE__, "id=#{model.id} model.cached?=#{model.cached?}" raise TypeError, "model.id #{model.id} already in cache" end @cached_ids << model.id RepoCache::Model.induct_to_cache(model, self, loaded_from_repo) model @@ -230,10 +236,10 @@ end end end def __debug(method, line, msg = nil) - s = "{__FILE__}[#{line}]:#{self.class.name}##{method}: #{msg}" + s = "#{__FILE__}[#{line}]:#{self.class.name}##{method}: #{msg}" if RUBY_PLATFORM == 'opal' Volt.logger.debug s else puts s end