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
- #remove(options = {}) ⇒ Object
- #remove_attribute(options = {}) ⇒ Object
- #remove_css_class(options = {}) ⇒ Object
- #replace(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",
focusSelector: "string",
html: "string"
}, ...],
inner_html: [{
selector: "string",
focusSelector: "string",
html: "string"
}, ...],
text_content: [{
selector: "string",
text: "string"
}, ...]
insert_adjacent_html: [{
selector: "string",
focusSelector: "string",
position: "string",
html: "string"
}, ...],
insert_adjacent_text: [{
selector: "string",
position: "string",
text: "string"
}, ...],
remove: [{
selector: "string",
focusSelector: "string,
}, ...],
replace: [{
selector: "string",
focusSelector: "string",
html: "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"
}, ...],
}
97 98 99 100 |
# File 'lib/cable_ready/channel.rb', line 97 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
157 158 159 |
# File 'lib/cable_ready/channel.rb', line 157 def add_css_class(={}) operations[:add_css_class] << end |
#broadcast ⇒ Object
106 107 108 109 110 111 |
# File 'lib/cable_ready/channel.rb', line 106 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
102 103 104 |
# File 'lib/cable_ready/channel.rb', line 102 def clear @operations = stub end |
#dispatch_event(options = {}) ⇒ Object
113 114 115 |
# File 'lib/cable_ready/channel.rb', line 113 def dispatch_event(={}) operations[:dispatch_event] << end |
#inner_html(options = {}) ⇒ Object
121 122 123 |
# File 'lib/cable_ready/channel.rb', line 121 def inner_html(={}) operations[:inner_html] << end |
#insert_adjacent_html(options = {}) ⇒ Object
129 130 131 |
# File 'lib/cable_ready/channel.rb', line 129 def insert_adjacent_html(={}) operations[:insert_adjacent_html] << end |
#insert_adjacent_text(options = {}) ⇒ Object
133 134 135 |
# File 'lib/cable_ready/channel.rb', line 133 def insert_adjacent_text(={}) operations[:insert_adjacent_text] << end |
#morph(options = {}) ⇒ Object
117 118 119 |
# File 'lib/cable_ready/channel.rb', line 117 def morph(={}) operations[:morph] << end |
#remove(options = {}) ⇒ Object
137 138 139 |
# File 'lib/cable_ready/channel.rb', line 137 def remove(={}) operations[:remove] << end |
#remove_attribute(options = {}) ⇒ Object
153 154 155 |
# File 'lib/cable_ready/channel.rb', line 153 def remove_attribute(={}) operations[:remove_attribute] << end |
#remove_css_class(options = {}) ⇒ Object
161 162 163 |
# File 'lib/cable_ready/channel.rb', line 161 def remove_css_class(={}) operations[:remove_css_class] << end |
#replace(options = {}) ⇒ Object
141 142 143 |
# File 'lib/cable_ready/channel.rb', line 141 def replace(={}) operations[:replace] << end |
#set_attribute(options = {}) ⇒ Object
149 150 151 |
# File 'lib/cable_ready/channel.rb', line 149 def set_attribute(={}) operations[:set_attribute] << end |
#set_dataset_property(options = {}) ⇒ Object
165 166 167 |
# File 'lib/cable_ready/channel.rb', line 165 def set_dataset_property(={}) operations[:set_dataset_property] << end |
#set_value(options = {}) ⇒ Object
145 146 147 |
# File 'lib/cable_ready/channel.rb', line 145 def set_value(={}) operations[:set_value] << end |
#text_content(options = {}) ⇒ Object
125 126 127 |
# File 'lib/cable_ready/channel.rb', line 125 def text_content(={}) operations[:text_content] << end |