Skip to content

Commit

Permalink
CBWIRE 4 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
grantcopley committed Apr 13, 2024
1 parent 110b510 commit 26593a9
Show file tree
Hide file tree
Showing 20 changed files with 768 additions and 46 deletions.
2 changes: 0 additions & 2 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ component {
interceptorSettings = {
customInterceptionPoints : [
"onCBWireMount",
"onCBWireRenderIt",
"onCBWireSubsequentRenderIt"
]
};
Expand All @@ -94,7 +93,6 @@ component {
// Mounting
{ class : "#moduleMapping#.interceptors.ComponentMounting" },
// Rendering
{ class : "#moduleMapping#.interceptors.InitialComponentRendering" },
{ class : "#moduleMapping#.interceptors.SubsequentComponentRendering" },
{ class : "#moduleMapping#.interceptors.AutoInjectAssets" },
// Output
Expand Down
8 changes: 6 additions & 2 deletions box.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
}
],
"contributors": [],
"dependencies": {},
"dependencies": {
"cbjavaloader": "^2.1.1+8"
},
"devDependencies": {
"commandbox-cfformat": "*",
"commandbox-docbox": "*"
Expand All @@ -42,5 +44,7 @@
"testbox": {
"runner": "http://localhost:60299/tests/runner.cfm"
},
"installPaths": {}
"installPaths": {
"cbjavaloader": "modules/cbjavaloader/"
}
}
21 changes: 11 additions & 10 deletions helpers/helpers.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
}
/**
* Instantiates our cbwire component, mounts it,
* and then calls it's internal renderIt() method.
*
* @componentName String | The name of the component to load.
* @parameters Struct | The parameters you want mounted initially.
*
* @return Component
*/
function wire( componentName, parameters = {}, key = "" ) {
return getInstance( "CBWireService@cbwire" ).wire( argumentCollection=arguments );
* Instantiates a CBWIRE component, mounts it,
* and then calls its internal renderIt() method.
*
* @param name The name of the component to load.
* @param params The parameters you want mounted initially. Defaults to an empty struct.
* @param key An optional key parameter. Defaults to an empty string.
*
* @return An instance of the specified component after rendering.
*/
function wire(required string name, struct params = {}, string key = "") {
return getInstance("CBWIREController@cbwire").wire( argumentCollection=arguments );
}
</cfscript>
10 changes: 0 additions & 10 deletions interceptors/InitialComponentRendering.cfc

This file was deleted.

8 changes: 8 additions & 0 deletions models/renderer/BaseRenderer.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1021,4 +1021,12 @@ component accessors="true" {
}
}

function getDataProperties(){
var props = variables.dataProperties;
// Merge properties defined with property tag
getParent().getPropertyTagDataProperties().each( function( prop ) {
props[ prop.name ] = getParent().getVariables()[ prop.name ];
} );
return props;
}
}
2 changes: 1 addition & 1 deletion models/renderer/RendererEncapsulator.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
return attributes.event.getController().getRenderer().view( argumentCollection=arguments );
};
getMetaData( attributes.cbwirecomponent.getParent() ).functions.each( function( cbwireFunction ) {
attributes.cbwirecomponent.getParent().getMetaInfo().functions.each( function( cbwireFunction ) {
variables[ cbwireFunction.name ] = function() {
return invoke( attributes.cbwireComponent.getParent(), cbwireFunction.name, arguments );
};
Expand Down
78 changes: 78 additions & 0 deletions models/v4/CBWIREController.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
component {

property name="wirebox" inject="wirebox";

/**
* Instantiates a CBWIRE component, mounts it,
* and then calls its internal renderIt() method.
*
* @param name The name of the component to load.
* @param params The parameters you want mounted initially. Defaults to an empty struct.
* @param key An optional key parameter. Defaults to an empty string.
*
* @return An instance of the specified component after rendering.
*/
function wire(required string name, struct params = {}, string key = "") {
return wirebox.getInstance("CBWIREController@cbwire")
.createInstance(argumentCollection=arguments)
._withParams( arguments.params )
._withKey( arguments.key )
._withHTTPRequestData( getHTTPRequestData() )
.renderIt();
}

/**
* Handles incoming AJAX requests to update or interact with CBWIRE components.
*
* @param payload The JSON string payload of the incoming request.
* @return A JSON string representing the response with updated component details or an error message.
*/
public string function handleRequest(required string payload) {
// Implementation of AJAX request handling
var data = deserializeJson(arguments.payload);
var responseComponents = [];
var isValidRequest = true;

// Example logic for processing a request
data.components.each(function(componentData) {
var componentInstance = createInstance(componentData.memo.name); // This method needs to be defined or adjusted according to your logic for instantiation
// Further processing...
});

if (!isValidRequest) {
return serializeJson({ "error": "Invalid request detected." });
}

return serializeJson({ "components": responseComponents });
}

/**
* Dynamically creates an instance of a CBWIRE component based on the provided name.
* Assumes components are located within a specific namespace or directory structure.
*
* @param componentName The name of the component to instantiate, possibly including a namespace.
* @param params Optional parameters to pass to the component constructor.
* @param key Optional key to use when retrieving the component from WireBox.
* @return The instantiated component object.
* @throws ApplicationException If the component cannot be found or instantiated.
*/
public any function createInstance(required string name ) {
// Determine if the component name traverses a valid namespace or directory structure
var fullComponentPath = arguments.name;

if (!fullComponentPath contains "wires.") {
fullComponentPath = "wires." & fullComponentPath;
}

try {
// Attempt to create an instance of the component
return wirebox.getInstance(fullComponentPath);
} catch (Any e) {
writeDump( e );
abort;
// Log error or handle it as needed
throw("ApplicationException", "Unable to instantiate component '#arguments.name#'. Detail: #e.message#");
}
}

}
Loading

0 comments on commit 26593a9

Please sign in to comment.