Class: React::IsomorphicHelpers::Context
- Defined in:
- lib/reactive-ruby/isomorphic_helpers.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#unique_id ⇒ Object
readonly
Returns the value of attribute unique_id.
Class Method Summary collapse
- .before_first_mount_blocks ⇒ Object
- .prerender_footer_blocks ⇒ Object
- .register_before_first_mount_block(&block) ⇒ Object
- .register_prerender_footer_block(&block) ⇒ Object
Instance Method Summary collapse
- #eval(js) ⇒ Object
-
#initialize(unique_id, ctx = nil, controller = nil, name = nil) ⇒ Context
constructor
A new instance of Context.
- #send_to_opal(method, *args) ⇒ Object
Constructor Details
#initialize(unique_id, ctx = nil, controller = nil, name = nil) ⇒ Context
Returns a new instance of Context.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 89 def initialize(unique_id, ctx = nil, controller = nil, name = nil) @unique_id = unique_id if RUBY_ENGINE != 'opal' @controller = controller @ctx = ctx ctx["ServerSideIsomorphicMethods"] = self send_to_opal(:load_context, @unique_id, name) end self.class.before_first_mount_blocks.each { |block| block.call(self) } end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
78 79 80 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 78 def controller @controller end |
#unique_id ⇒ Object (readonly)
Returns the value of attribute unique_id.
79 80 81 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 79 def unique_id @unique_id end |
Class Method Details
.before_first_mount_blocks ⇒ Object
81 82 83 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 81 def self.before_first_mount_blocks @before_first_mount_blocks ||= [] end |
.prerender_footer_blocks ⇒ Object
85 86 87 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 85 def self. ||= [] end |
.register_before_first_mount_block(&block) ⇒ Object
111 112 113 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 111 def self.register_before_first_mount_block(&block) before_first_mount_blocks << block end |
.register_prerender_footer_block(&block) ⇒ Object
115 116 117 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 115 def self.(&block) << block end |
Instance Method Details
#eval(js) ⇒ Object
100 101 102 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 100 def eval(js) @ctx.eval(js) if @ctx end |
#send_to_opal(method, *args) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/reactive-ruby/isomorphic_helpers.rb', line 104 def send_to_opal(method, *args) return unless @ctx args = [1] if args.length == 0 ::ReactiveRuby::ComponentLoader.new(@ctx).load! @ctx.eval("Opal.React.$const_get('IsomorphicHelpers').$#{method}(#{args.collect { |arg| "'#{arg}'"}.join(', ')})") end |