Skip to content

Commit

Permalink
Merge pull request #63 from bjanderson70/master
Browse files Browse the repository at this point in the history
Needed Code Coverage > 75%
  • Loading branch information
ImJohnMDaniel authored Feb 1, 2021
2 parents ca71a5f + 676573e commit 6e11ae2
Show file tree
Hide file tree
Showing 22 changed files with 999 additions and 152 deletions.
16 changes: 14 additions & 2 deletions config/enterprise-project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{
"orgName": "Acme DF18 Enterprise Company",
"orgName": "force-di-scratch-ent",
"edition": "Enterprise",
"features": ["MultiCurrency","AuthorApex"],
"settings": {
"communitiesSettings": {
"enableNetworksEnabled": false
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
},
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
"enableS1DesktopEnabled": true
},
"securitySettings": {
"sessionSettings":{
"sessionTimeout": "TwelveHours"
}
}
}
}
16 changes: 14 additions & 2 deletions config/project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
{
"orgName": "force-di",
"orgName": "force-di-scratch-dev",
"edition": "Developer",
"features": ["MultiCurrency","AuthorApex"],
"settings": {
"communitiesSettings": {
"enableNetworksEnabled": false
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
},
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
"enableS1DesktopEnabled": true
},
"securitySettings": {
"sessionSettings":{
"sessionTimeout": "TwelveHours"
}
}
}
}
5 changes: 5 additions & 0 deletions force-di/main/aura/di_injector/di_injector.cmp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

<aura:component controller="di_InjectorController">
<aura:attribute name="bindingName" type="String" required="true"/>
<!-- BJA for container id -->
<aura:attribute name="bindingId" type="String" required="false"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<!-- Added by Leon Kempers: Listen to attribute value change -->
<aura:handler name="attributeChangeEvent" event="c:di_injectorAttributeChangeEvent" action="{!c.handleChangeEvent}" includeFacets="true" />

{!v.body}
</aura:component>
38 changes: 38 additions & 0 deletions force-di/main/aura/di_injector/di_injectorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,29 @@
// Resolve the given binding
var action = cmp.get("c.getBinding");
action.setParams({ bindingName : cmp.get("v.bindingName") });

action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var bindingInfo = response.getReturnValue();
var injectAttrs = cmp.get("v.body");

// Construct attributes to pass on to injected component
var componentName = null;
var componentAttrs = {};


if(bindingInfo.BindingTypeAsString == 'Flow') {
componentName = 'c:di_injectorFlowProxy';
componentAttrs['flowName'] = bindingInfo.To;
componentAttrs['injectorAttributes'] = injectAttrs;
} else if(bindingInfo.BindingTypeAsString == 'LightningComponent') {
// Added by Leon Kempers: set aura:id
let bindingId = cmp.get('v.bindingId');
if (typeof bindingId === 'undefined') {
cmp.set('v.bindingId', 'di_component');
}
componentAttrs['aura:id'] = cmp.get('v.bindingId');
componentName = bindingInfo.To;
for (var attrIdx in injectAttrs) {
var injectAttr = injectAttrs[attrIdx];
Expand All @@ -52,6 +62,7 @@
console.log("Binding type " + bindingInfo.BindingTypeAsString + ' not supported');
return;
}

// Inject the component bound to the given binding
$A.createComponent(
componentName,
Expand Down Expand Up @@ -88,5 +99,32 @@
}
});
$A.enqueueAction(action);
},

// Added by Leon Kempers: Listen to attribute value change
//
// added a handler to capture the di_injectorAttributeChangeEvent. When it comes in,
// the handleChangeEvent() function looks at the bindingId variable stored in the component,
// finds the component based on this ID, and changes the specified attribute to the 'newValue'.
//
// The only not-so-pretty thing here is that sometimes (e.g. in case of the spinner) the value
// changed while $A.createComponent was still running (i.e. the Lightning Component hadn't
// been put on the DOM yet). So in that case, we just wait 100ms and try again.
handleChangeEvent : function(component, event, helper) {

let bindingId = component.get('v.bindingId');
let auraCmp = component.find(bindingId);

// Sometimes value will change while the Aura Component hasn't
// been added to the DOM yet; wait 100ms and try again
if (typeof(auraCmp) === undefined) {
setTimeout(function() {
this.handleChangeEvent(component, event, helper);
}, 100);
} else {
let name = event.getParam('name');
let newValue = event.getParam('newValue');
auraCmp.set('v.' + name, newValue);
}
}
})
14 changes: 14 additions & 0 deletions force-di/main/aura/di_injectorAttribute/di_injectorAttribute.cmp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@
description="Specific data type the value represents. Helps when mapping values to things like input variables of flows."
required="false"/>

<!-- Added by Leon Kempers: Register attribute value change

fix the issue where attribute values passed to a Lightning Component were only
set upon initialization, and subsequent changes were not handled

added a change handler for the "value" attribute, and registered the
di_injectorAttributeChangeEvent. When the "value" attribute changes, it fires
the di_injectorAttributeChangeEvent, and passes along the name and the new value
of the changed attribute
-->
<aura:handler name="change" value="{!v.value}" action="{!c.handleValueChange}"/>
<aura:registerevent name="attributeChangeEvent" type="c:di_injectorAttributeChangeEvent" />


</aura:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
({
// Leon Kempers - handle dynamic value change via event
handleValueChange : function(component, event, helper) {
let name = component.get('v.name');
let newValue = event.getParam('value');

let changeEvent = component.getEvent('attributeChangeEvent');
changeEvent.setParams({ 'name' : name, 'newValue' : newValue });
changeEvent.fire();
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Added Event - Leon Kempers
Component Event to indicate when an attribute value has changed
-->
<aura:event type="COMPONENT" description="Event for sending information to encapsulated component">
<aura:attribute name="name" type="String" />
<aura:attribute name="newValue" type="String" />
</aura:event>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<description>A Lightning Event Bundle</description>
</AuraDefinitionBundle>
1 change: 0 additions & 1 deletion force-di/main/classes/di_Binding.cls
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ public abstract class di_Binding implements Comparable {
{
if ( this.bindings == null )
{
System.debug('// di_Binding.Resolver :: Loading Bindings //');
// Ask each module to configure and aggregate the resulting bindings
this.bindings = new List<di_Binding>();
for (di_Module module : modules)
Expand Down
21 changes: 11 additions & 10 deletions force-di/main/classes/di_Injector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ public class di_Injector {
public static final di_Injector Org =
new di_Injector(
new List<di_Module> {
new CustomMetadataModule()});
new CustomMetadataModule()
});

/**
* Bindings visible to this Injector
**/
@TestVisible
public di_Binding.Resolver Bindings {get; private set;}

/**
Expand Down Expand Up @@ -84,7 +86,6 @@ public class di_Injector {
if ( String.isBlank(developerName) ) {
throw new InjectorException('Request for Binding cannot take "developerName" parameter of null');
}

List<di_Binding> bindingsFound = this.Bindings.byName( developerName.toLowerCase().trim() ).get();
if ( bindingsFound == null || bindingsFound.isEmpty() ) {
throw new InjectorException('Binding for "' + developerName + '" not found');
Expand Down Expand Up @@ -121,8 +122,8 @@ public class di_Injector {
}

List<di_Binding> bindingsFound = this.Bindings.bySObject( bindingSObjectType )
.byName( developerName.toLowerCase().trim() )
.get();
.byName( developerName.toLowerCase().trim() )
.get();

if ( bindingsFound == null || bindingsFound.isEmpty() || bindingsFound[0] == null) {
throw new InjectorException('Binding for "' + developerName + '" and SObjectType "' + bindingSObjectType + '" not found');
Expand Down Expand Up @@ -152,23 +153,23 @@ public class di_Injector {
, BindingObject__r.QualifiedApiName
, BindingObjectAlternate__c
, BindingSequence__c
FROM di_Binding__mdt];
for(di_Binding__mdt records :bindingMDTRec){
FROM di_Binding__mdt];
for(di_Binding__mdt records :bindingMDTRec) {
recordList.add(new di_BindingConfigWrapper(records));
}
// When we want to mock data from metadata for injecting dependencies.
if(di_Injector.mock_BindingConfigurationWrappersOuter != null){
if(di_Injector.mock_BindingConfigurationWrappersOuter != null) {
recordList = di_Injector.mock_BindingConfigurationWrappersOuter;
}
return recordList;
}
public override void configure() {
// TODO: Support Namespace
for(di_BindingConfigWrapper bindingConfig :getDIBinding()){
for(di_BindingConfigWrapper bindingConfig :getDIBinding()) {
bind(bindingConfig.DeveloperName);
type(bindingConfig.Type);
if( String.isNotBlank(bindingConfig.BindingObject)
|| String.isNotBlank(bindingConfig.BindingObjectAlternate)){
|| String.isNotBlank(bindingConfig.BindingObjectAlternate)) {
bindingObjectApiName = String.isNotBlank(bindingConfig.BindingObject)
? bindingConfig.bindingObjectQualifiedApiName.toLowerCase().trim()
: bindingConfig.BindingObjectAlternate.toLowerCase().trim();
Expand All @@ -178,7 +179,7 @@ public class di_Injector {
}
bind(results[0].getSObjectType()); // if it is getting here, then it is finding a SObject to add to the binding
}
if(bindingConfig.BindingSequence != null){
if(bindingConfig.BindingSequence != null) {
sequence(Integer.valueOf(bindingConfig.BindingSequence));
}
data(bindingConfig);
Expand Down
11 changes: 6 additions & 5 deletions force-di/main/classes/di_InjectorComponentController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
**/

public with sharing class di_InjectorComponentController {

public String BindingNameValue {set;get;}

public Object ParametersValue {set;get;}
public String BindingNameValue {set; get;}
// BJA - container id for lightning-- allows consumers to reference into (optional)
public String BindingIdValue {set; get;}
public Object ParametersValue {set; get;}

public ApexPages.Component getInject() {
ApexPages.Component cmp = null;
Expand Down Expand Up @@ -56,7 +57,7 @@ public with sharing class di_InjectorComponentController {
return new Component.di_injectorFlowProxy(
flowName = flowName,
inputVariables = params
);
);
}

}
Loading

0 comments on commit 6e11ae2

Please sign in to comment.