-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de86eba
commit 5df9f88
Showing
7 changed files
with
101 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,70 @@ | ||
component { | ||
/* | ||
There is code duplication here, but I'm not sure how to avoid it. | ||
We need to be able to parse the arguments passed to the emit() and emitTo() methods | ||
and there are differences between how Lucee and Adobe CF handle the arguments. | ||
/** | ||
* Parse out emit arguments and parameters | ||
*/ | ||
function parseEmitArguments( required eventName ){ | ||
var argumentsRef = arguments; | ||
Creating separate functions for each method allows us to handle the differences | ||
here. | ||
*/ | ||
component accessors="true" { | ||
|
||
return argumentsRef.reduce( function( agg, argument ){ | ||
if ( isNull( argumentsRef[ argument ] ) || argument == "ComponentName" ) { | ||
return agg; | ||
} | ||
property name="caller"; | ||
|
||
var value = argumentsRef[ argument ]; | ||
function parseEmitParameters( required eventName ) { | ||
|
||
if ( argument == "eventName" ) return agg; | ||
var selfArguments = arguments; | ||
|
||
if ( isObject( value ) ) { | ||
return agg; | ||
} else { | ||
agg.append( value ); | ||
} | ||
return selfArguments | ||
.keyList() | ||
.listToArray() | ||
// Remove any arguments called "eventName" from the list | ||
.filter( function( value ) { | ||
return value != "eventName" && value != "componentName"; | ||
} ) | ||
// Sort the arguments by their numeric value | ||
.sort( "numeric" ) | ||
// Convert the sorted list back to an ordered struct | ||
.reduce( function( acc, value, index ) { | ||
acc[ value ] = selfArguments[value]; | ||
return acc; | ||
}, [:] ) | ||
// Filter out any null or object values | ||
.filter( function( key, value ) { | ||
return !isNull( value ) && !isObject( value ); | ||
} ) | ||
// Convert the struct to an array which makes up our parameters | ||
.reduce( function( acc, key, value, thisStruct ) { | ||
acc.append( value ); | ||
return acc; | ||
}, [] ); | ||
} | ||
|
||
function parseEmitToParameters( required componentName, required eventName ) { | ||
var selfArguments = arguments; | ||
|
||
return agg; | ||
}, [] ); | ||
return selfArguments | ||
.keyList() | ||
.listToArray() | ||
// Remove any arguments called "eventName" from the list | ||
.filter( function( value ) { | ||
return value != "eventName" && value != "componentName"; | ||
} ) | ||
// Sort the arguments by their numeric value | ||
.sort( "numeric" ) | ||
// Convert the sorted list back to an ordered struct | ||
.reduce( function( acc, value, index ) { | ||
acc[ value ] = selfArguments[value]; | ||
return acc; | ||
}, [:] ) | ||
// Filter out any null or object values | ||
.filter( function( key, value ) { | ||
return !isNull( value ) && !isObject( value ); | ||
} ) | ||
// Convert the struct to an array which makes up our parameters | ||
.reduce( function( acc, key, value, thisStruct ) { | ||
acc.append( value ); | ||
return acc; | ||
}, [] ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
component extends="BaseEmitConcern" singleton { | ||
component extends="BaseEmitConcern" { | ||
|
||
function handle( comp, eventName ){ | ||
var localParameters = parseEmitArguments( argumentCollection = arguments ); | ||
function handle( required eventName ){ | ||
|
||
var emitParameters = parseEmitParameters( argumentCollection = arguments ); | ||
|
||
var emitter = { | ||
"event" : arguments.eventName, | ||
"params" : localParameters, | ||
"params" : emitParameters, | ||
"selfOnly" : true | ||
}; | ||
|
||
// Capture the emit as we will need to notify the UI in our response | ||
arguments.comp.trackEmit( emitter ); | ||
getCaller().trackEmit( emitter ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
component extends="BaseEmitConcern" singleton { | ||
component extends="BaseEmitConcern" { | ||
|
||
function handle( comp, componentName, eventName ){ | ||
var localParameters = parseEmitArguments( argumentCollection = arguments ); | ||
function handle( required componentName, required eventName ){ | ||
var emitParameters = parseEmitToParameters( argumentCollection = arguments ); | ||
|
||
var emitter = { | ||
"event" : arguments.eventName, | ||
"params" : localParameters, | ||
"params" : emitParameters, | ||
"to" : arguments.componentName | ||
}; | ||
|
||
// Capture the emit as we will need to notify the UI in our response | ||
arguments.comp.trackEmit( emitter ); | ||
getCaller().trackEmit( emitter ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
component extends="BaseEmitConcern" singleton { | ||
|
||
function handle( comp, eventName ){ | ||
var localParameters = parseEmitArguments( argumentCollection = arguments ); | ||
component extends="BaseEmitConcern" { | ||
|
||
function handle( required eventName ){ | ||
var emitParameters = parseEmitParameters( argumentCollection = arguments ); | ||
var emitter = { | ||
"event" : arguments.eventName, | ||
"params" : localParameters, | ||
"params" : emitParameters, | ||
"ancestorsOnly" : true | ||
}; | ||
|
||
// Capture the emit as we will need to notify the UI in our response | ||
arguments.comp.trackEmit( emitter ); | ||
getCaller().trackEmit( emitter ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters