Prefetching
You can prefetch an action's results on mouseOver using the .prefetch modifier.
1
// File: ./views/wires/movie.cfm
2
<div>
3
<button wire:click.prefetch="togglePreview">Show Preview</button>
4
5
<cfif args.showPreview>
6
<!-- Preview goes here -->
7
</cfif>
8
</div>
Copied!
1
// File: ./wires/Movie.cfc
2
component extends="cbwire.models.Component"{
3
4
variables.data = {
5
"showPreview": false
6
};
7
8
function togglePreview(){
9
variables.data.contentIsVisible = true;
10
}
11
12
function renderIt(){
13
return this.renderView( "wires/movie" );
14
}
15
}
Copied!
In the example here, cbwire will invoke ( prefetch ) the togglePreview action when the user mouses over the button. The results of the fetch are not displayed until the user clicks the 'Show Preview' button.
Prefetching works well for actions that do not perform any side effects, such as mutating session data or writing to a database. If the action you are "pre-fetching" does have side effects, you may encounter unpredictable results.
Last modified 2mo ago
Copy link
Edit on GitHub