Created
October 25, 2016 20:46
-
-
Save mtetlow/dd7439cd53ec6d787a08458e8c0560bf to your computer and use it in GitHub Desktop.
Object Mutation with Locker Service enabled
This file contains 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 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> |
This file contains 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
({ | |
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