Draft: Listen to cable-ready:after-update events and re-request the partial#120
Draft: Listen to cable-ready:after-update events and re-request the partial#120xtr3me wants to merge 2 commits intostimulusreflex:masterfrom
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. |
| } | ||
| } | ||
|
|
||
| const targetResolver = (event) => { |
There was a problem hiding this comment.
I have to check if this is still needed or a relic of my try & fail & try again approach
javascript/package.json
Outdated
| "homepage": "https://github.com/stimulusreflex/futurism#readme", | ||
| "dependencies": { | ||
| "cable_ready": "5.0.0-pre8" | ||
| "cable_ready": "file:../../cable_ready" |
…ement to not morph but instead emit an event
c8ddc14 to
78b5bef
Compare
| @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.
Not really happy with this variable name, any suggestions?
| @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.
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.
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.
Remove this and include it from CableReady once it's moved to a module.
|
|
||
| private | ||
|
|
||
| def wrapped_html(html, options) |
There was a problem hiding this comment.
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: