-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ember.run.once running several times when method is an anonymous function #12369
Comments
When passing an anonymous function to once, it receives a new function each time. This prevents the once check from being possible, since it is getting a legitimate new function. I believe this is covered in the run-loop guide. If not be sure to open an issue on the guide/website repo |
That totally makes sense, but the docs should be updated. |
looks like the issue was introduced emberjs/website@ddbc9bc |
opened an issue, with suggestions for the fix. emberjs/guides#776 Maybe you have some free cycles to test your new undestanding of |
Also for reference, the API docs are accurate: http://emberjs.com/api/classes/Ember.run.html#method_scheduleOnce |
extra comment to ensure no confusion i the API docs: #12373 |
Thanks, in the API docs http://emberjs.com/api/classes/Ember.run.html#method_scheduleOnce I would have just replaced |
OK got it, sorry, the docs for http://emberjs.com/api/classes/Ember.run.html#method_scheduleOnce are correct and the anonymous function case is dealt with, unfortunately I was only looking at the doc for the .once function without checking scheduleOnce: http://emberjs.com/api/classes/Ember.run.html#method_once So technically, the docs are correct.. Replacing |
I'm not good for jsfiddles, but the below is pretty clear:
``` javascript````
export default Ember.Controller.extend({
..
_test1: function(){
var arr=[1,1,1,1,1,1,1,1,1];
var self=this;
arr.forEach(function(i){
Ember.run.once(self,'_testlog');
});
},
_testlog: function(){
console.log("_testlog");
},
_test2: function(){
var arr=[1,1,1,1,1,1,1,1,1];
var self=this;
arr.forEach(function(i){
Ember.run.once(self,function(){
this._testlog();
});
});
},
});
So this behaviour is very confusing and doesn't fit with the docs: http://emberjs.com/api/classes/Ember.run.html#method_once
tested with Ember 1.12.1.
note:
arr and the forEach loop have no impact here, I just created them to show a clear example
note2:
if I want to use a function as a method for
Ember.run.once
, it is because I want to nest anEmber.run.next
inside it without writing still another CP for the Ember.run.next: there is noEmber.run.onceNext
method available, while I tend to use it everywhere in my app (this is different thanEmber.run.scheduleOnce('destroy',..)
note3:
I had the same kind of confusing behavior with store.filter, where if I remember well I had in that case to use a function for the method, and not a property string to make it work.
The text was updated successfully, but these errors were encountered: