Skip to content

Instantly share code, notes, and snippets.

@mtetlow
Created October 25, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtetlow/dd7439cd53ec6d787a08458e8c0560bf to your computer and use it in GitHub Desktop.
Save mtetlow/dd7439cd53ec6d787a08458e8c0560bf to your computer and use it in GitHub Desktop.
Object Mutation with Locker Service enabled
<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<aura:attribute name="lockedObj" type="Object" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<button onclick="{!c.addAtributeViaMutation}">Add Attribute via mutation then simple set</button>
<button onclick="{!c.addAtributeDeepSet}">Add Attribute via deep set</button>
<button onclick="{!c.log}">Log</button>
<div>Existing Attribute: {!v.lockedObj.existingAttribute}</div>
<div>New Attribute via mutation: {!v.lockedObj.newAttribute}</div>
<div>New Attribute via deep set: {!v.lockedObj.newAttributeDeep}</div>
</aura:component>
({
doInit : function(component, event, helper){
var initialObject = {existingAttribute: 'Existing'};
component.set('v.lockedObj',initialObject);
},
addAtributeViaMutation : function(component, event, helper){
var obj = component.get('v.lockedObj');
obj.newAttribute = 'New';
component.set('v.lockedObj',obj);
},
addAtributeDeepSet : function(component, event, helper) {
component.set('v.lockedObj.newAttributeDeep', 'New');
component.set('v.lockedObj.wat', 'wat???');
},
log : function(component, event, helper){
console.log(component.get('v.lockedObj'));
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment