Class: CableReady::Channel
- Inherits:
-
Object
- Object
- CableReady::Channel
- Defined in:
- lib/cable_ready/channel.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
- #add_css_class(options = {}) ⇒ Object
- #broadcast ⇒ Object
- #clear ⇒ Object
- #dispatch_event(options = {}) ⇒ Object
-
#initialize(name) ⇒ Channel
constructor
Example Operations Payload:.
- #inner_html(options = {}) ⇒ Object
- #insert_adjacent_html(options = {}) ⇒ Object
- #insert_adjacent_text(options = {}) ⇒ Object
- #morph(options = {}) ⇒ Object
- #outer_html(options = {}) ⇒ Object
- #remove(options = {}) ⇒ Object
- #remove_attribute(options = {}) ⇒ Object
- #remove_css_class(options = {}) ⇒ Object
- #set_attribute(options = {}) ⇒ Object
- #set_dataset_property(options = {}) ⇒ Object
- #set_value(options = {}) ⇒ Object
- #text_content(options = {}) ⇒ Object
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,
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"
}, ...],
}
98 99 100 101 |
# File 'lib/cable_ready/channel.rb', line 98 def initialize(name) @name = name @operations = stub end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/cable_ready/channel.rb', line 3 def name @name end |
#operations ⇒ Object (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
158 159 160 |
# File 'lib/cable_ready/channel.rb', line 158 def add_css_class( = {}) operations[:add_css_class] << end |
#broadcast ⇒ Object
107 108 109 110 111 112 |
# File 'lib/cable_ready/channel.rb', line 107 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 |
#clear ⇒ Object
103 104 105 |
# File 'lib/cable_ready/channel.rb', line 103 def clear @operations = stub end |
#dispatch_event(options = {}) ⇒ Object
114 115 116 |
# File 'lib/cable_ready/channel.rb', line 114 def dispatch_event( = {}) operations[:dispatch_event] << end |
#inner_html(options = {}) ⇒ Object
122 123 124 |
# File 'lib/cable_ready/channel.rb', line 122 def inner_html( = {}) operations[:inner_html] << end |
#insert_adjacent_html(options = {}) ⇒ Object
134 135 136 |
# File 'lib/cable_ready/channel.rb', line 134 def insert_adjacent_html( = {}) operations[:insert_adjacent_html] << end |
#insert_adjacent_text(options = {}) ⇒ Object
138 139 140 |
# File 'lib/cable_ready/channel.rb', line 138 def insert_adjacent_text( = {}) operations[:insert_adjacent_text] << end |
#morph(options = {}) ⇒ Object
118 119 120 |
# File 'lib/cable_ready/channel.rb', line 118 def morph( = {}) operations[:morph] << end |
#outer_html(options = {}) ⇒ Object
126 127 128 |
# File 'lib/cable_ready/channel.rb', line 126 def outer_html( = {}) operations[:outer_html] << end |
#remove(options = {}) ⇒ Object
142 143 144 |
# File 'lib/cable_ready/channel.rb', line 142 def remove( = {}) operations[:remove] << end |
#remove_attribute(options = {}) ⇒ Object
154 155 156 |
# File 'lib/cable_ready/channel.rb', line 154 def remove_attribute( = {}) operations[:remove_attribute] << end |
#remove_css_class(options = {}) ⇒ Object
162 163 164 |
# File 'lib/cable_ready/channel.rb', line 162 def remove_css_class( = {}) operations[:remove_css_class] << end |
#set_attribute(options = {}) ⇒ Object
150 151 152 |
# File 'lib/cable_ready/channel.rb', line 150 def set_attribute( = {}) operations[:set_attribute] << end |
#set_dataset_property(options = {}) ⇒ Object
166 167 168 |
# File 'lib/cable_ready/channel.rb', line 166 def set_dataset_property( = {}) operations[:set_dataset_property] << end |
#set_value(options = {}) ⇒ Object
146 147 148 |
# File 'lib/cable_ready/channel.rb', line 146 def set_value( = {}) operations[:set_value] << end |
#text_content(options = {}) ⇒ Object
130 131 132 |
# File 'lib/cable_ready/channel.rb', line 130 def text_content( = {}) operations[:text_content] << end |