Skip to content

Commit

Permalink
Restore onUpdate functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
grantcopley committed Sep 13, 2024
1 parent 44d9760 commit b69950f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions models/Component.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ component output="true" {
* @return void
*/
function _applyUpdates( updates ) {
// Capture old values
local.oldValues = duplicate( data );
// Array to track which array props were updated
local.updatedArrayProps = [];
// Loop over the updates and apply them
Expand Down Expand Up @@ -765,6 +767,11 @@ component output="true" {
return arguments.value != "__rm__";
} );
} );

// Call onUpdate passing newValues and oldValues
if ( structKeyExists( this, "onUpdate" ) ) {
invoke( this, "onUpdate", { newValues: duplicate( variables.data ), oldValues: local.oldValues } );
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,25 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( snapshot.memo.children.count() ).toBe( 1 );
} );

it(" should call onUpdate if it exists", function() {
var payload = incomingRequest(
memo = {
"name": "test.should_call_onupdate",
"id": "Z1Ruz1tGMPXSfw7osBW2",
"children": []
},
data = {
"cbwireVersion": 3
},
calls = [],
updates = {
"cbwireVersion": 4
}
);
var response = cbwireController.handleRequest( payload, event );
expect( response.components[1].effects.html ).toInclude( "onUpdateCalled: true" );
} );

it( "should call onUpdate[Property] if it exists", function() {
var payload = incomingRequest(
memo = {
Expand Down
20 changes: 20 additions & 0 deletions test-harness/wires/test/should_call_onupdate.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<cfoutput>
<div>
<h1>Should Call OnUpdate</h1>
<p>
onUpdateCalled: #onUpdateCalled#
</p>
</div>
</cfoutput>

<cfscript>
// @startWire
data = {
"onUpdateCalled": false
};
function onUpdate( newValues, oldValues ){
data.onUpdateCalled = true;
}
// @endWire
</cfscript>

0 comments on commit b69950f

Please sign in to comment.