Skip to content

Commit

Permalink
#144 Breaking Change: Update Event Emission for Array Parameters in C…
Browse files Browse the repository at this point in the history
…BWIRE 4
  • Loading branch information
grantcopley committed Jan 26, 2024
1 parent 914212f commit de86eba
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 0 additions & 4 deletions models/concerns/BaseEmitConcern.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ component {

if ( isObject( value ) ) {
return agg;
} else if ( isArray( value ) ) {
value.each( function( nestedArgument ){
agg.append( nestedArgument );
} );
} else {
agg.append( value );
}
Expand Down
8 changes: 3 additions & 5 deletions models/renderer/BaseRenderer.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,9 @@ component accessors="true" {
setFinishedUpload( true );
getDirtyProperties().append( params[ 1 ] );
emitSelf(
eventName = "upload:finished",
parameters = [
params[ 1 ],
[ "nf48Fr0I6Buvk6DnxBLbDVw7W2NMtO-metaMjAyMi0wOC0yMSAwNy41Mi41MC5naWY=-.gif" ]
]
"upload:finished",
params[ 1 ],
[ "nf48Fr0I6Buvk6DnxBLbDVw7W2NMtO-metaMjAyMi0wOC0yMSAwNy41Mi41MC5naWY=-.gif" ]
);
}

Expand Down
4 changes: 1 addition & 3 deletions models/updates/CallMethod.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ component extends="BaseUpdate" {
* @return Void
*/
function apply( required comp ){
// arguments.comp._renderComputedProperties();

if ( getPayloadMethod() == "finishUpload" ) {
arguments.comp.finishUpload( params = getPassedParamsAsArguments() );
return;
Expand All @@ -27,7 +25,7 @@ component extends="BaseUpdate" {
var dataProperty = getName();
var signature = "someSignature";
var signedURL = "/livewire/upload-file?expires=never&signature=#signature#";
comp.emitSelf( eventName = "upload:generatedSignedUrl", parameters = [ dataProperty, signedURL ] );
comp.emitSelf( "upload:generatedSignedUrl", dataProperty, signedURL );
return;
}

Expand Down
20 changes: 17 additions & 3 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ component extends="coldbox.system.testing.BaseTestCase" {
expect( firstEmit.params[ 2 ] ).toBe( "arg2" );
expect( firstEmit.params[ 3 ] ).toBe( "arg3" );
} );

it( "can pass an array as a single argument", function() {
rc.updates = [ {
type: "CallMethod",
payload: {
method: "emitEventWithArrayArg"
}
} ];
comp.$( "getComponentTemplatePath", "/tests/templates/dataproperty.cfm" );
var result = renderSubsequent( comp );
var firstEmit = result.effects.emits[ 1 ];
expect( firstEmit.event ).toBe( "Event1" );
expect( isArray( firstEmit.params[ 1 ] ) ).toBeTrue();
} );
} );

describe( "emitSelf()", function() {
Expand Down Expand Up @@ -628,9 +642,9 @@ component extends="coldbox.system.testing.BaseTestCase" {
var result = renderSubsequent( comp );
var firstEmit = result.effects.emits[ 1 ];
expect( firstEmit.event ).toBe( "Event1" );
expect( firstEmit.params[ 1 ] ).toBe( "arg1" );
expect( firstEmit.params[ 2 ] ).toBe( "arg2" );
expect( firstEmit.params[ 3 ] ).toBe( "arg3" );
expect( firstEmit.params[ 1 ][ 1 ] ).toBe( "arg1" );
expect( firstEmit.params[ 1 ][ 2 ] ).toBe( "arg2" );
expect( firstEmit.params[ 1 ][ 3 ] ).toBe( "arg3" );
expect( firstEmit.selfOnly ).toBeTrue();
} );
} );
Expand Down
8 changes: 6 additions & 2 deletions test-harness/tests/templates/TestComponent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ component extends="cbwire.models.Component" {
}

function emitEventWithManyArgs() {
emit( "Event1", "arg1", "arg2", "arg3" );
}

function emitEventWithArrayArg(){
emit( "Event1", [ "arg1", "arg2", "arg3" ] );
}

Expand All @@ -117,7 +121,7 @@ component extends="cbwire.models.Component" {
}

function emitUpEventWithManyArgs() {
emitUp( "Event1", [ "arg1", "arg2", "arg3" ] );
emitUp( "Event1", "arg1", "arg2", "arg3" );
}

function emitToEventWithoutArgs() {
Expand All @@ -129,7 +133,7 @@ component extends="cbwire.models.Component" {
}

function emitToEventWithManyArgs() {
emitTo( "Component2", "Event1", [ "arg1", "arg2", "arg3" ] );
emitTo( "Component2", "Event1", "arg1", "arg2", "arg3" );
}

function doNotRender() {
Expand Down

0 comments on commit de86eba

Please sign in to comment.