• Arturs
  • NEWBIE
  • 10 Points
  • Member since 2016
  • TA and Dev
  • Better Cloud Solutions Ltd


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 4
    Replies
Hi,
I am trying to use javascript promises to perform multi-step asynchronous operations in lightning components. Unfortuantely I am stuck with the problem where the promise behaves incorrectly within $A.getCallback context. Here is a simplified app and js controller to demostrate the problem.

I have a simple app definition with a string attribute that defaults to "superman".
<aura:application >
    
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
            
    <aura:attribute name="myatt" type="String" required="false" default="superman" access="private"  />

</aura:application>

Associated controller.js code uses Promises:
({
	init : function( cmp, evt, h) {

        Promise.resolve(1).then($A.getCallback(function(val) {
                console.log('val %o', val);
                return new Promise($A.getCallback(function(done, err){
                    setTimeout($A.getCallback(function(){
                        // console.log('now!');
                        done('yo ' + cmp.get('v.myatt'));
                    }), 2000);
                }));
                // return 'yo ' + cmp.get('v.myatt');
        })).then($A.getCallback(function(res){
            console.log('Result: %o', res);
        }));
    }
})
When locker service is disabled, the console log outputs an expected output (notice that Result appears after 2 seconds):
​val 1
Result: "yo superman"
However, when Locker Service is enabled, the Result becomes javascript Object with no useful attributes that is returned immediatly:
val 1
Result: Object
(When object is expanded)
-> $then$: function ()
-> __proto__: Object

I would really like to utilise the power of promises as it's a nightmare to use callbacks all the time. Any ideas?


 
  • November 02, 2016
  • Like
  • 0
Hi,

ltng:require stopped loading CSS resources. Page inspection reveals empty <link> elements added to the page.

Worked in Summer 16, doesn't work in Winter 17
<ltng:require styles="{! $Resource.MyCSS }" />
Any workarounds till this is fixed?
  • October 19, 2016
  • Like
  • 0
Hi,
I am trying to use javascript promises to perform multi-step asynchronous operations in lightning components. Unfortuantely I am stuck with the problem where the promise behaves incorrectly within $A.getCallback context. Here is a simplified app and js controller to demostrate the problem.

I have a simple app definition with a string attribute that defaults to "superman".
<aura:application >
    
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
            
    <aura:attribute name="myatt" type="String" required="false" default="superman" access="private"  />

</aura:application>

Associated controller.js code uses Promises:
({
	init : function( cmp, evt, h) {

        Promise.resolve(1).then($A.getCallback(function(val) {
                console.log('val %o', val);
                return new Promise($A.getCallback(function(done, err){
                    setTimeout($A.getCallback(function(){
                        // console.log('now!');
                        done('yo ' + cmp.get('v.myatt'));
                    }), 2000);
                }));
                // return 'yo ' + cmp.get('v.myatt');
        })).then($A.getCallback(function(res){
            console.log('Result: %o', res);
        }));
    }
})
When locker service is disabled, the console log outputs an expected output (notice that Result appears after 2 seconds):
​val 1
Result: "yo superman"
However, when Locker Service is enabled, the Result becomes javascript Object with no useful attributes that is returned immediatly:
val 1
Result: Object
(When object is expanded)
-> $then$: function ()
-> __proto__: Object

I would really like to utilise the power of promises as it's a nightmare to use callbacks all the time. Any ideas?


 
  • November 02, 2016
  • Like
  • 0
Hi,

ltng:require stopped loading CSS resources. Page inspection reveals empty <link> elements added to the page.

Worked in Summer 16, doesn't work in Winter 17
<ltng:require styles="{! $Resource.MyCSS }" />
Any workarounds till this is fixed?
  • October 19, 2016
  • Like
  • 0
​I keep getting

Challenge Not yet complete... here's what's wrong: 
The 'Top Laptop Industry' lens was not found. Please follow the requirements and ensure everything is setup correctly


I have named the Lens as step 2 - Enter D01 - Laptops Salespeople - Wall of Fame as the title AND/OR result set Top Laptop Industry

Neither seem to work. I have refresed the screen, even cleared cookies and rebooted the computer.