Skip to content

Instantly share code, notes, and snippets.

@michalvavra
Last active May 8, 2018 16:37
Show Gist options
  • Select an option

  • Save michalvavra/61618710479ee2e151579aa3edbe06e7 to your computer and use it in GitHub Desktop.

Select an option

Save michalvavra/61618710479ee2e151579aa3edbe06e7 to your computer and use it in GitHub Desktop.
<aura:application>
<c:state context="{!this}" />
<force:recordData aura:id="contactRecordHandler"
layoutType="FULL"
recordId="{!state.contactId}"
targetFields="{!state.contact}"
targetError="{!state.contactErrors}"
mode="EDIT"
/>
<h1>{!state.contact.Name}</h1>
</aura:application>
<aura:component>
<aura:attribute name="context" type="Object" access="public" required="true" />
<aura:handler name="init" value="{!this}" action="{!c.onInit}" />
<aura:attribute name="contactId" type="Id" default="0035800000hYmZzAAK" />
<aura:attribute name="contact" type="Contact" />
<aura:attribute name="contactErrors" type="String[]" />
</aura:component>
({
onInit: function(component, event, helper) {
const context = component.get('v.context');
const valueProvider = {
get: function(key, contextComponent) {
const attributeName = 'v.' + key;
const value = component.get(attributeName);
if ($A.util.isUndefined(value)) {
console.error(`${contextComponent.getType()}: Attribute "${key}" can not be get. It is not defined in "${component.getType()}" component`);
}
return value;
},
set: function(key, newValue, contextComponent) {
const attributeName = 'v.' + key;
const oldValue = component.get(attributeName);
if ($A.util.isUndefined(oldValue)) {
console.error(`${contextComponent.getType()}: Attribute "${key}" can not be set. It is not defined in "${component.getType()}" component`);
}
component.set(attributeName, newValue);
}
}
context.addValueProvider('state', valueProvider);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment