Class: HyperMesh::ClientDrivers

Inherits:
Object
  • Object
show all
Includes:
React::IsomorphicHelpers
Defined in:
lib/synchromesh/client_drivers.rb

Class Method Summary collapse

Class Method Details

.get_queued_data(operation, channel = nil, opts = {}) ⇒ Object



291
292
293
294
295
296
297
# File 'lib/synchromesh/client_drivers.rb', line 291

def self.get_queued_data(operation, channel = nil, opts = {})
  HTTP.get(polling_path(operation, channel), opts).then do |response|
    response.json.each do |update|
      send "sync_#{update[0]}", update[1]
    end
  end
end

.opts ⇒ Object



275
276
277
# File 'lib/synchromesh/client_drivers.rb', line 275

def self.opts
  @opts ||= Hash.new(`window.HyperMeshOpts`)
end

.polling_path(to, id = nil) ⇒ Object



351
352
353
354
355
# File 'lib/synchromesh/client_drivers.rb', line 351

def self.polling_path(to, id = nil)
  s = "#{`window.ReactiveRecordEnginePath`}/synchromesh-#{to}/#{opts[:id]}"
  s = "#{s}/#{id}" if id
  s
end

.public_columns_hash ⇒ Object



285
286
287
288
289
# File 'lib/synchromesh/client_drivers.rb', line 285

def self.public_columns_hash
  # return {} unless @opts && @opts[:public_columns_hash]
  # @opts[:public_columns_hash]
  @public_columns_hash ||= get_public_columns_hash
end

.sync_change(data) ⇒ Object



219
220
221
222
223
224
225
# File 'lib/synchromesh/client_drivers.rb', line 219

def self.sync_change(data)
  IncomingBroadcast.receive(data, :change) do |broadcast|
    ReactiveRecord::Base.when_not_saving(broadcast.klass) do
      ReactiveRecord::Collection.sync_scopes broadcast
    end
  end
end

.sync_create(data) ⇒ Object

sync_changes: Wait till we are done with any concurrent model saves, then hydrate the data (which will update any attributes) and sync the scopes.



211
212
213
214
215
216
217
# File 'lib/synchromesh/client_drivers.rb', line 211

def self.sync_create(data)
  IncomingBroadcast.receive(data, :create) do |broadcast|
    ReactiveRecord::Base.when_not_saving(broadcast.klass) do
      ReactiveRecord::Collection.sync_scopes broadcast
    end
  end
end

.sync_destroy(data) ⇒ Object

sync_destroy: Hydrate the data, then destroy the record, cleanup and syncronize the scopes.



230
231
232
233
234
# File 'lib/synchromesh/client_drivers.rb', line 230

def self.sync_destroy(data)
  IncomingBroadcast.receive(data, :destroy) do |broadcast|
    ReactiveRecord::Collection.sync_scopes broadcast
  end
end