Class: React::IsomorphicHelpers::IsomorphicProcCall
- Defined in:
- lib/reactive-ruby/isomorphic_helpers.rb
Instance Method Summary collapse
-
#initialize(name, block, *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, *args) ⇒ IsomorphicProcCall
Returns a new instance of IsomorphicProcCall.
133 134 135 136 137 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 133 def initialize(name, block, *args) @name = name block.call(self, *args) @result ||= send_to_server(*args) if IsomorphicHelpers.on_opal_server? end |
Instance Method Details
#result ⇒ Object
129 130 131 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 129 def result @result.first if @result end |
#send_to_server(*args) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 143 def send_to_server(*args) if IsomorphicHelpers.on_opal_server? args_as_json = args.to_json @result = [JSON.parse(`Opal.global.ServerSideIsomorphicMethods[#{@name}](#{args_as_json})`)] end end |
#when_on_client(&block) ⇒ Object
139 140 141 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 139 def when_on_client(&block) @result = [block.call] if IsomorphicHelpers.on_opal_client? end |
#when_on_server(&block) ⇒ Object
150 151 152 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 150 def when_on_server(&block) @result = [block.call.to_json] unless IsomorphicHelpers.on_opal_client? || IsomorphicHelpers.on_opal_server? end |