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.
132 133 134 135 136 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 132 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
128 129 130 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 128 def result @result.first if @result end |
#send_to_server(*args) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 142 def send_to_server(*args) if IsomorphicHelpers.on_opal_server? args_as_json = args.to_json @result = [JSON.parse(`window.ServerSideIsomorphicMethods[#{@name}](#{args_as_json})`)] end end |
#when_on_client(&block) ⇒ Object
138 139 140 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 138 def when_on_client(&block) @result = [block.call] if IsomorphicHelpers.on_opal_client? end |
#when_on_server(&block) ⇒ Object
149 150 151 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 149 def when_on_server(&block) @result = [block.call.to_json] unless IsomorphicHelpers.on_opal_client? || IsomorphicHelpers.on_opal_server? end |