Class: CableReady::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/cable_ready/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Channel

Example Operations Payload:

{

# DOM Events ..................................................................................................

dispatch_event: [{
  name:     "string",
  detail:   "object",
  selector: "string",
}, ...],

# Element Mutations ...........................................................................................

morph: [{
  selector:      "string",
  html:          "string"
  children_only:  true|false,
  permanent_attribute_name: "string",
  focus_selector: "string",
}, ...],

inner_html: [{
  selector:      "string",
  focus_selector: "string",
  html:          "string"
}, ...],

outer_html: [{
  selector:      "string",
  focus_selector: "string",
  html:          "string"
}, ...],

text_content: [{
  selector: "string",
  text:     "string"
}, ...]

insert_adjacent_html: [{
  selector:      "string",
  focus_selector: "string",
  position:      "string",
  html:          "string"
}, ...],

insert_adjacent_text: [{
  selector: "string",
  position: "string",
  text:     "string"
}, ...],

remove: [{
  selector:      "string",
  focus_selector: "string,
}, ...],

set_value: [{
  selector: "string",
  value:    "string"
}, ...],

# Attribute Mutations .........................................................................................

set_attribute: [{
  selector: "string",
  name:     "string",
  value:    "string"
}, ...],

remove_attribute: [{
  selector: "string",
  name:     "string"
}, ...],

# CSS Class Mutations .........................................................................................

add_css_class: [{
  selector: "string",
  name:     "string"
}, ...],

remove_css_class: [{
  selector: "string",
  name:     "string"
}, ...],

# Dataset Mutations ...........................................................................................

set_dataset_property: [{
  selector: "string",
  name:     "string",
  value:    "string"
}, ...],

}



99
100
101
102
# File 'lib/cable_ready/channel.rb', line 99

def initialize(name)
  @name = name
  @operations = stub
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/cable_ready/channel.rb', line 3

def name
  @name
end

#operationsObject (readonly)

Returns the value of attribute operations.



3
4
5
# File 'lib/cable_ready/channel.rb', line 3

def operations
  @operations
end

Instance Method Details

#add_css_class(options = {}) ⇒ Object



159
160
161
# File 'lib/cable_ready/channel.rb', line 159

def add_css_class(options = {})
  operations[:add_css_class] << options
end

#broadcastObject



108
109
110
111
112
113
# File 'lib/cable_ready/channel.rb', line 108

def broadcast
  operations.select! { |_, list| list.present? }
  operations.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
  ActionCable.server.broadcast name, "cableReady" => true, "operations" => operations
  clear
end

#clearObject



104
105
106
# File 'lib/cable_ready/channel.rb', line 104

def clear
  @operations = stub
end

#dispatch_event(options = {}) ⇒ Object



115
116
117
# File 'lib/cable_ready/channel.rb', line 115

def dispatch_event(options = {})
  operations[:dispatch_event] << options
end

#inner_html(options = {}) ⇒ Object



123
124
125
# File 'lib/cable_ready/channel.rb', line 123

def inner_html(options = {})
  operations[:inner_html] << options
end

#insert_adjacent_html(options = {}) ⇒ Object



135
136
137
# File 'lib/cable_ready/channel.rb', line 135

def insert_adjacent_html(options = {})
  operations[:insert_adjacent_html] << options
end

#insert_adjacent_text(options = {}) ⇒ Object



139
140
141
# File 'lib/cable_ready/channel.rb', line 139

def insert_adjacent_text(options = {})
  operations[:insert_adjacent_text] << options
end

#morph(options = {}) ⇒ Object



119
120
121
# File 'lib/cable_ready/channel.rb', line 119

def morph(options = {})
  operations[:morph] << options
end

#outer_html(options = {}) ⇒ Object



127
128
129
# File 'lib/cable_ready/channel.rb', line 127

def outer_html(options = {})
  operations[:outer_html] << options
end

#remove(options = {}) ⇒ Object



143
144
145
# File 'lib/cable_ready/channel.rb', line 143

def remove(options = {})
  operations[:remove] << options
end

#remove_attribute(options = {}) ⇒ Object



155
156
157
# File 'lib/cable_ready/channel.rb', line 155

def remove_attribute(options = {})
  operations[:remove_attribute] << options
end

#remove_css_class(options = {}) ⇒ Object



163
164
165
# File 'lib/cable_ready/channel.rb', line 163

def remove_css_class(options = {})
  operations[:remove_css_class] << options
end

#set_attribute(options = {}) ⇒ Object



151
152
153
# File 'lib/cable_ready/channel.rb', line 151

def set_attribute(options = {})
  operations[:set_attribute] << options
end

#set_dataset_property(options = {}) ⇒ Object



167
168
169
# File 'lib/cable_ready/channel.rb', line 167

def set_dataset_property(options = {})
  operations[:set_dataset_property] << options
end

#set_value(options = {}) ⇒ Object



147
148
149
# File 'lib/cable_ready/channel.rb', line 147

def set_value(options = {})
  operations[:set_value] << options
end

#text_content(options = {}) ⇒ Object



131
132
133
# File 'lib/cable_ready/channel.rb', line 131

def text_content(options = {})
  operations[:text_content] << options
end