module RenderSync::ModelRenderSyncing
Private Instance Methods
prepare_sync_create()
click to toggle source
# File lib/render_sync/model_syncing.rb, line 6 def prepare_sync_create add_sync_action(:new, self, default_scope: sync_default_scope) sync_scope_definitions.each do |definition| scope = RenderSync::Scope.new_from_model(definition, self) if scope.contains?(self) add_sync_action :new, self, scope: scope, default_scope: sync_default_scope end end end
prepare_sync_destroy()
click to toggle source
# File lib/render_sync/model_syncing.rb, line 25 def prepare_sync_destroy add_sync_action :destroy, self, default_scope: sync_default_scope sync_scope_definitions.each do |definition| scope = RenderSync::Scope.new_from_model(definition, self) if scope.valid? add_sync_action :destroy, self, scope: scope, default_scope: sync_default_scope end end end
prepare_sync_update()
click to toggle source
# File lib/render_sync/model_syncing.rb, line 17 def prepare_sync_update add_sync_action :update, self sync_scope_definitions.each do |definition| prepare_sync_update_scope(definition) end end
prepare_sync_update_scope(scope_definition)
click to toggle source
Creates update actions for subscribers on the sync scope defined by the passed sync scope definition.
It compares the state of the record in context of the sync scope before and after the update. If the record has been added to a scope, it publishes a new partial to the subscribers of that scope. It also sends a destroy action to subscribers of the scope, if the record has been removed from it.
# File lib/render_sync/model_syncing.rb, line 47 def prepare_sync_update_scope(scope_definition) # Add destroy action for the old scope (scope_before_update) # if this record has left it if left_old_scope?(scope_definition) add_sync_action :destroy, record_before_update, scope: scope_before_update(scope_definition), default_scope: sync_default_scope end # Add new action for the new scope (scope_after_update) if this record has entered it if entered_new_scope?(scope_definition) add_sync_action :new, record_after_update, scope: scope_after_update(scope_definition), default_scope: sync_default_scope end end