Module: LiveCable::Component::ReactiveVariables

Extended by:
ActiveSupport::Concern
Included in:
LiveCable::Component
Defined in:
lib/live_cable/component/reactive_variables.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaults_appliedBoolean (readonly)

Returns:

  • (Boolean)


122
123
124
# File 'lib/live_cable/component/reactive_variables.rb', line 122

def defaults_applied
  @defaults_applied
end

Instance Method Details

#all_reactive_variablesObject



82
83
84
# File 'lib/live_cable/component/reactive_variables.rb', line 82

def all_reactive_variables
  self.class.all_reactive_variables
end

#apply_defaultsObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/live_cable/component/reactive_variables.rb', line 102

def apply_defaults
  # Don't set defaults more than once
  return if defaults_applied

  defaults = (self.defaults || {}).symbolize_keys
  keys = all_reactive_variables & defaults.keys

  keys.each do |key|
    public_send("#{key}=", defaults[key])
  end

  @defaults_applied = true
end

#defaults=(defaults) ⇒ Object



98
99
100
# File 'lib/live_cable/component/reactive_variables.rb', line 98

def defaults=(defaults)
  @defaults = (defaults || {}).symbolize_keys
end

#dirty(*variables) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/live_cable/component/reactive_variables.rb', line 86

def dirty(*variables)
  variables.each do |variable|
    unless all_reactive_variables.include?(variable)
      raise LiveCable::Error, "Invalid reactive variable: #{variable}"
    end

    container_name = self.class.reactive_variables.include?(variable) ? live_id : Connection::SHARED_CONTAINER

    live_connection.dirty(container_name, variable)
  end
end

#prerender_containerHash

Returns:

  • (Hash)


117
118
119
# File 'lib/live_cable/component/reactive_variables.rb', line 117

def prerender_container
  @prerender_container ||= {}
end