module ServerComponent::Component
Public Instance Methods
action(*action_names, &block)
click to toggle source
# File lib/server_component/component.rb, line 68 def action(*action_names, &block) options = action_names.extract_options! raise ArgumentError, 'specify at least one action!' if action_names.empty? action_names.each do |action_name| action_descriptors[action_name.to_sym] = {} end fetcher(*action_names, &block) if block if options[:on_mount] raise ArgumentError, 'on_mount option can accept only one action' if action_names.size > 1 on_mount action_names.first end end
action_descriptors()
click to toggle source
# File lib/server_component/component.rb, line 58 def action_descriptors if instance_variable_defined?('@action_descriptors') instance_variable_get '@action_descriptors' else h = {} instance_variable_set '@action_descriptors', h h end end
before(*actions, &block)
click to toggle source
# File lib/server_component/component.rb, line 92 def before(*actions, &block) fetcher(*actions) do |c| c.before(&block) end end
fetcher(*actions) { |configurator| ... }
click to toggle source
# File lib/server_component/component.rb, line 87 def fetcher(*actions) configurator = FetcherConfigurator.new(self, actions.map(&:to_sym)) yield configurator end
on_mount(action)
click to toggle source
# File lib/server_component/component.rb, line 83 def on_mount(action) self.action_on_mount = action end
set_state(&block)
click to toggle source
Calls superclass method
# File lib/server_component/component.rb, line 42 def set_state(&block) # rubocop:disable Naming/AccessorMethodName jsrb = Jsrb::Base.new super(jsrb, &block) render jsrb: jsrb.generate_code end
to_json()
click to toggle source
# File lib/server_component/component.rb, line 50 def to_json { action_on_mount: action_on_mount, initial_state: initial_state, actions: action_descriptors } end