Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 8cf6b09

Browse files
committed
prerendering working
1 parent 293ccff commit 8cf6b09

File tree

8 files changed

+19
-39
lines changed

8 files changed

+19
-39
lines changed

lib/active_record_base.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module ActiveRecord
33
# 1 - Setup synchronization after commits
44
# 2 - Update scope to accept different procs for server and client
55
class Base
6+
67
class << self
78

89
def _synchromesh_scope_args_check(args)
@@ -43,13 +44,6 @@ def default_scope(*args, &block)
4344

4445
else
4546

46-
include React::IsomorphicHelpers
47-
48-
before_first_mount do
49-
@_default_scope = nil
50-
@_unscoped = nil
51-
end
52-
5347
alias pre_synchromesh_method_missing method_missing
5448

5549
def method_missing(name, *args, &block)
@@ -83,7 +77,7 @@ def default_scope(*args, &block)
8377
end
8478

8579
def all
86-
@_default_scope ||=
80+
ReactiveRecord::Base.default_scope[self] ||=
8781
if @_default_scopes
8882
root = ReactiveRecord::Collection
8983
.new(self, nil, nil, self, 'all')
@@ -99,7 +93,7 @@ def all=(_collection)
9993
end
10094

10195
def unscoped
102-
@_unscoped ||=
96+
ReactiveRecord::Base.unscoped[self] ||=
10397
ReactiveRecord::Collection
10498
.new(self, nil, nil, self, 'unscoped')
10599
.extend(ReactiveRecord::UnscopedCollection)

lib/reactive_record/base.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ def self.exists?(model, id)
6363
class << self
6464
attr_reader :outer_scopes
6565

66+
def default_scope
67+
@class_scopes[:default_scope]
68+
end
69+
70+
def unscoped
71+
@class_scopes[:unscoped]
72+
end
73+
6674
def add_to_outer_scopes(item)
6775
@outer_scopes << item
6876
end

lib/reactive_record/collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def reload_from_db(force = nil)
222222
end
223223

224224
def observed
225-
return if @observing
225+
return if @observing || ReactiveRecord::Base.data_loading?
226226
begin
227227
@observing = true
228228
link_to_parent

lib/reactive_record/synchromesh_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def subscribe
9696
end
9797

9898
def read
99-
data = Synchromesh::Connection.read(client_id)
99+
root_path = request.original_url.gsub(/synchromesh-read.*$/, '')
100+
data = Synchromesh::Connection.read(client_id, root_path)
100101
render json: data
101102
end
102103

@@ -127,7 +128,7 @@ def connect_to_transport
127128
def console_update
128129
authorization = Synchromesh.authorization(params[:salt], params[:channel], params[:data][1][:broadcast_id]) #params[:data].to_json)
129130
return head :unauthorized if authorization != params[:authorization]
130-
Synchromesh::Connection.send(params[:channel], params[:data])
131+
Synchromesh::Connection.send_to_channel(params[:channel], params[:data])
131132
head :no_content
132133
rescue
133134
head :unauthorized

lib/synchromesh/client_drivers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def self.get_queued_data(operation, channel = nil, opts = {})
292292
`ActionCable.createConsumer.apply(ActionCable, #{[*opts[:action_cable_consumer_url]]})`
293293
Synchromesh.connect(*opts[:auto_connect])
294294
elsif opts[:transport] == :simple_poller
295-
opts[:auto_connect].each { |channel| IncomingBroadcast.add_connection *channel }
295+
opts[:auto_connect].each { |channel| IncomingBroadcast.add_connection(*channel) }
296296
every(opts[:seconds_between_poll]) do
297297
get_queued_data(:read, nil, headers: {'X-SYNCHROMESH-SILENT-REQUEST': true })
298298
end

lib/synchromesh/connection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def send_to_channel(channel, data)
9797
transport.send(channel, data) if exists?(channel: channel, session: nil)
9898
end
9999

100-
def read(session)
100+
def read(session, root_path)
101+
self.root_path = root_path
101102
where(session: session)
102103
.update_all(expires_at: Time.now + transport.expire_polled_connection_in)
103104
QueuedMessage.for_session(session).destroy_all.pluck(:data)

lib/synchromesh/synchromesh.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def self.authorization(salt, channel, session_id)
137137
)
138138
end
139139

140-
def self.run_after_commit(operation, model)
140+
def self.after_commit(operation, model)
141141
InternalPolicy.regulate_broadcast(model) do |data|
142142
if Synchromesh.on_console? && Connection.root_path
143143
Synchromesh.send_to_server(data[:channel], [operation, data])
@@ -147,20 +147,5 @@ def self.run_after_commit(operation, model)
147147
end
148148
end
149149

150-
@queue = Queue.new
151-
Thread.new do
152-
loop do
153-
run_after_commit(*@queue.pop)
154-
end
155-
end
156-
157-
def self.after_commit(*args)
158-
if true || on_console?
159-
run_after_commit(*args)
160-
else
161-
@queue.push args
162-
end
163-
end
164-
165150
Connection.transport = self
166151
end

spec/synchromesh/examples/scoped_todos_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def render
135135
user2.comments << FactoryGirl.create(:comment, comment: "bob made this comment", todo: user1.assigned_todos.first)
136136
# evaluate_ruby do
137137
# Synchromesh::IncomingBroadcast.hypertrace do
138-
# #instrument :merge_current_values
139138
# break_on_exit?(:merge_current_values) { Todo.find(5).comments.last.todo.nil? rescue nil }
140139
# end
141140
# ReactiveRecord::ScopeDescription.hypertrace do
@@ -152,17 +151,9 @@ def render
152151
wait_for_ajax
153152
page.should_not have_content('MANAGER SAYS: Me BOSS', wait: 0)
154153
page.should_not have_content('BOSS SAYS: Me BOSS', wait: 0)
155-
#pause
156-
# evaluate_ruby do
157-
# ReactiveRecord::Collection.hypertrace(instrument: :all)
158-
# end
159-
#pause
160-
#puts "here we go!!!!!!!!!!"
161154
user1.update_attribute(:manager, mgr)
162-
#puts evaluate_ruby "User.find(#{user1.id}).update_attribute(:manager, #{mgr.id})"
163155
page.should have_content('MANAGER SAYS: Me BOSS')
164156
page.should have_content('BOSS SAYS: Me BOSS')
165157
evaluate_ruby("ReactiveRecord::Base.last_fetch_at").should eq(starting_fetch_time)
166-
#pause
167158
end
168159
end

0 commit comments

Comments
 (0)