Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace_state and go operations #101

Merged
merged 5 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions javascript/cable_ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,18 @@ const DOMOperations = {
dispatch(document, 'cable-ready:after-clear-storage', operation)
},

go: operation => {
dispatch(window, 'cable-ready:before-go', operation)
const { delta } = operation
if (!operation.cancel) history.go(delta)
dispatch(window, 'cable-ready:after-go', operation)
},

pushState: operation => {
dispatch(document, 'cable-ready:before-push-state', operation)
dispatch(window, 'cable-ready:before-push-state', operation)
const { state, title, url } = operation
if (!operation.cancel) history.pushState(state || {}, title || '', url)
dispatch(document, 'cable-ready:after-push-state', operation)
dispatch(window, 'cable-ready:after-push-state', operation)
},

removeStorageItem: operation => {
Expand All @@ -311,6 +318,13 @@ const DOMOperations = {
dispatch(document, 'cable-ready:after-remove-storage-item', operation)
},

replaceState: operation => {
dispatch(window, 'cable-ready:before-replace-state', operation)
const { state, title, url } = operation
if (!operation.cancel) history.replaceState(state || {}, title || '', url)
dispatch(window, 'cable-ready:after-replace-state', operation)
},

scrollIntoView: operation => {
const { element } = operation
dispatch(element, 'cable-ready:before-scroll-into-view', operation)
Expand All @@ -326,8 +340,8 @@ const DOMOperations = {
},

setFocus: operation => {
const { element } = operation
dispatch(element, 'cable-ready:before-set-focus', operation)
const { element } = operation
if (!operation.cancel) assignFocus(element)
dispatch(element, 'cable-ready:after-set-focus', operation)
},
Expand Down
2 changes: 2 additions & 0 deletions lib/cable_ready/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def default_operation_names
clear_storage
console_log
dispatch_event
go
graft
inner_html
insert_adjacent_html
Expand All @@ -49,6 +50,7 @@ def default_operation_names
remove_css_class
remove_storage_item
replace
replace_state
scroll_into_view
set_attribute
set_cookie
Expand Down