Last active
May 8, 2018 16:37
-
-
Save michalvavra/61618710479ee2e151579aa3edbe06e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <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> |
This file contains hidden or 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
| <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> |
This file contains hidden or 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
| ({ | |
| 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