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

Commit a17ac3e

Browse files
committed
added context to isomorphic proc call
1 parent d6667fa commit a17ac3e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/reactive-ruby/isomorphic_helpers.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ def self.register_prerender_footer_block(&block)
136136
end
137137

138138
class IsomorphicProcCall
139+
140+
attr_reader :context
141+
139142
def result
140143
@result.first if @result
141144
end
142145

143-
def initialize(name, block, *args)
146+
def initialize(name, block, context, *args)
144147
@name = name
148+
@context = context
145149
block.call(self, *args)
146150
@result ||= send_to_server(*args) if IsomorphicHelpers.on_opal_server?
147151
end
@@ -190,18 +194,19 @@ def prerender_footer(&block)
190194
if RUBY_ENGINE != 'opal'
191195
def isomorphic_method(name, &block)
192196
React::IsomorphicHelpers::Context.send(:define_method, name) do |args_as_json|
193-
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, *JSON.parse(args_as_json)).result
197+
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, self, *JSON.parse(args_as_json)).result
194198
end
195199
end
196200
else
197201
require 'json'
198202

199203
def isomorphic_method(name, &block)
200204
self.class.send(:define_method, name) do | *args |
201-
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, *args).result
205+
React::IsomorphicHelpers::IsomorphicProcCall.new(name, block, self, *args).result
202206
end
203207
end
204208
end
209+
205210
end
206211
end
207212
end

0 commit comments

Comments
 (0)