coldbox-modules / cbwire

CBWIRE is a ColdBox module that makes building reactive, modern apps easy using HTML-over-the-wire technologies and CFML.
https://cbwire.ortusbooks.com
Other
28 stars 5 forks source link

Add ability to refresh all child components from the parent component when an action is called #117

Closed grantcopley closed 1 year ago

grantcopley commented 1 year ago

The current default for cbwire is to never refresh the child components, but sometimes you want to force the child components to refresh.

Here's a component that dynamically tries to display a child component based on the data property 'mycomponent'.

<cfscript>
    data = {
        "mycomponent": "component1"
    }

    function setComponent( componentName ) {
        data.mycomponent = arguments.componentName;
    }
</cfscript>

<cfoutput>
    <div>
        #mycomponent# #now()#
        <h1>Loader</h1>
        <button wire:click="setComponent( 'component1' )">Component 1</button>
        <button wire:click="setComponent( 'component2' )">Component 2</button>

        #wire( mycomponent )#
    </div>
</cfoutput>

This does not work.

Add the ability to call 'refresh()' within an action for force child components to re-render.

    function setComponent( componentName ) {
        data.mycomponent = arguments.componentName;
        refresh();
    }