-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Draft: Listen to cable-ready:after-update events and re-request the partial #120
base: master
Are you sure you want to change the base?
Draft: Listen to cable-ready:after-update events and re-request the partial #120
Conversation
I'm currently pondering whether this should be opt-in. Honestly we have a long list of optional attributes already so I'm rather leaning on making this default behavior, albeit we should then probably remember to make CR >= 5 a hard dependency (which it is going to be anyway) |
I've updated the PR and tried the changes locally. This solution works but it has a drawback:
The following things still need to be checked / altered:
See the stimulusreflex/cable_ready#166 PR for the changes needed within the CableReady updates-for HTML element. |
@@ -16,6 +16,10 @@ const debounceEvents = (callback, delay = 20) => { | |||
} | |||
} | |||
|
|||
const targetResolver = (event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to check if this is still needed or a relic of my try & fail & try again approach
javascript/package.json
Outdated
@@ -22,7 +22,7 @@ | |||
}, | |||
"homepage": "https://github.com/stimulusreflex/futurism#readme", | |||
"dependencies": { | |||
"cable_ready": "5.0.0-pre8" | |||
"cable_ready": "file:../../cable_ready" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to restore this
…ement to not morph but instead emit an event
c8ddc14
to
78b5bef
Compare
@html_options = options.delete(:html_options) || {} | ||
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params) | ||
@model = options.delete(:model) | ||
@wrapped_for_updates_for = options.delete(:wrapped_for_updates_for) | ||
if @wrapped_for_updates_for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really happy with this variable name, any suggestions?
@html_options = options.delete(:html_options) || {} | ||
@data_attributes = html_options.fetch(:data, {}).except(:sgid, :signed_params) | ||
@model = options.delete(:model) | ||
@wrapped_for_updates_for = options.delete(:wrapped_for_updates_for) | ||
if @wrapped_for_updates_for | ||
@html_options[:keep] = 'keep' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to not add the IntersectionObserver (as it will re-request the partial over and over again when it is visible)
@wrapped_for_updates_for = options.delete(:wrapped_for_updates_for) | ||
if @wrapped_for_updates_for | ||
@html_options[:keep] = 'keep' | ||
@data_attributes['updates-for'] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instructing the javascript to listen for the CableReady cable-ready:after-update
event. As we only want to refresh the partial if it has been rendered before.
private | ||
|
||
############ | ||
# TODO: Include CableReadyHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this and include it from CableReady once it's moved to a module.
|
||
yield(resource_definition.selector, html, resource_definition.broadcast_each) | ||
end | ||
end | ||
|
||
private | ||
|
||
def wrapped_html(html, options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name of this method can be improved
Type of PR
feature / enhancement
Description
By listening to cable-ready:after-update events we are able to re-request the partial from the server. Allowing the server to serve the original content (without the need for unless) and stay fast.
Why should this be added
The server can serve it's original response without needing to include the futurismed partials which can potentially be slow to render. (That is probably the reason why futurism was chosen, at least it is in my case).
Checklist
This is currently a proposal / draft. I still need to try/test this locally and remove the found caveats.
I would like to get feedback on the proposed code in order to improve it / check if this would be the correct way to implement this enhancement.
Potential caveats are: