How to use $A.set() or how to add a custom global value provider?

I am a little bit confused. Knowing that not all features which are available in a pure aura project are exposed to Lightning Components I thought it is mandatory to check against the Salesforce developer documentation.

So in the auradocs/reference.app below the JavaScript API section I found the function $A.set() giving this example:

$A.set("$Custom.something","new Value")

Unfortunately this does not work, giving me an error “Unable to set value for key”. So my assumption is that I have to define a global value provider with the appropriate key first. When you search the Salesforce developer documentation against global value provider you get the first result showing up:

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_global_value_providers_custom.htm?search_text=global%20value%20provider

It seems that the search result is not within the scope of the Lightning Components as it does not show up in the navigation.

Does anyone have an idea how

  • $A.set() is working
  • I can add a custom global value provider or any other mechanism to store data in a manner known as Singleton

Thanks in advance

Chris

Answer

$A.set() isn’t exposed in Lightning Experience.

You can check this blog post re: client-side shared singleton (across components):

https://developer.salesforce.com/blogs/developer-relations/2016/12/lightning-components-code-sharing.html

Attribution
Source : Link , Question Author : Christian Menzinger , Answer Author : muenzpraeger

Leave a Comment