Class: React::IsomorphicHelpers::IsomorphicProcCall
- Defined in:
- lib/reactive-ruby/isomorphic_helpers.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(name, block, context, *args) ⇒ IsomorphicProcCall
constructor
A new instance of IsomorphicProcCall.
- #result ⇒ Object
- #send_to_server(*args) ⇒ Object
- #when_on_client(&block) ⇒ Object
- #when_on_server(&block) ⇒ Object
Constructor Details
#initialize(name, block, context, *args) ⇒ IsomorphicProcCall
Returns a new instance of IsomorphicProcCall.
167 168 169 170 171 172 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 167 def initialize(name, block, context, *args) @name = name @context = context block.call(self, *args) @result ||= send_to_server(*args) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
161 162 163 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 161 def context @context end |
Instance Method Details
#result ⇒ Object
163 164 165 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 163 def result @result.first if @result end |
#send_to_server(*args) ⇒ Object
178 179 180 181 182 183 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 178 def send_to_server(*args) if IsomorphicHelpers.on_opal_server? method_string = "ServerSideIsomorphicMethod." + @name + "(" + args.to_json + ")" @result = [JSON.parse(`eval(method_string)`)] end end |
#when_on_client(&block) ⇒ Object
174 175 176 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 174 def when_on_client(&block) @result = [block.call] if IsomorphicHelpers.on_opal_client? end |
#when_on_server(&block) ⇒ Object
185 186 187 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 185 def when_on_server(&block) @result = [block.call.to_json] unless IsomorphicHelpers.on_opal_client? || IsomorphicHelpers.on_opal_server? end |