The setTimeout() function in Sencha Touch does not work. It executes the code immediately as setTimeout is called. Has anybody had experience / has a workaround for this bug?
Why not use Ext.Functions.defer; (Short: Ext.defer)
// this syntax is sometimes useful for deferring execution of an anonymous function:
Ext.defer(function(){}, millisecs, scope);
// defer the answer 100ms with the current scope
Ext.defer(function() {
alert('Anonymous');
}, 100, this);
Defer is the variant of SetTimeout function in Sencha
Ext.Function.defer(function () {
alert('Anonymous');
}, 5000);
Related
It will have a callback function called repeatedly to when I start a download task. But It will be so slow that it can't give feedback when touch a button.
Fileio.downloadFile(downloadData[downloadFileIndex].uri, '1.jpg',this.progressFunc.bind(this)).then((DownloadResult)=> {
if (DownloadResult.statusCode == 200) {
let nextDownloadFileIndex = this.props.downloadFileIndex + 1;
this.props.dispatch(DOWNLOADED_A_FILE({
downloadFileIndex:nextDownloadFileIndex,
progressNum:0
}))
}
}).catch((error)=> {
console.log(error)
})
This is my code and the callback function are as be folllowed
progressFunc(DownloadBeginCallbackResult) {
let progressNum = DownloadBeginCallbackResult.bytesWritten / DownloadBeginCallbackResult.contentLength;
if(progressNum<=0.99){
this.props.dispatch(DOWNLOADING_A_FILE({
progressNum:progressNum,
jobId:this.props.jobId
}));
}else{
this.props.dispatch(DOWNLOADING_A_FILE({
progressNum:0,
jobId:this.props.jobId
}));
}
}
I mean I can't get feedback immediately when I touch button. I think that it is because I have a callback function called repeatedly. so js can't handle so many tasks;
It does sound like JS thread is busy doing the request and not able to communicate back to UI thread. One thing you can try is to wrap you on press handler in an InteractionManager.runAfterInteractions(() => ...)
See https://facebook.github.io/react-native/docs/interactionmanager.html
I stated to work with vue.js recently and I don't understand why this behavior happens, using the setTimeout(). With the following code, the function defined in setInterval(function(), time) is launched immediately no matter the value of 'time':
timerOn(){
...
this.avatar.timer.data = setTimeout( this.timerFunction(), 10000);
},
timerFunction(){
...
console.log('Hello!!');
clearTimeout(this.avatar.timer.data);
this.timerOn();
},
But if I use the following code all works fine and the function inside setInterval occurs after the 'time' defined:
timerOn(){
...
var This = this;
this.avatar.timer.data = setTimeout(function() { This.timerFunction()}, 10000);
},
timerFunction(){
...
console.log('Hello!!');
clearTimeout(this.avatar.timer.data);
this.timerOn();
},
Someone can guide me and say why the first method fails?
Thank you.
This executes timerFunction immediately and passes the result as the callback to setTimeout.
setTimeout( this.timerFunction(), 10000)
But, you want to pass a callback to setTimeout and timerFunction does not return a function. I expect what you wanted was
setTimeout( this.timerFunction, 10000)
This passes a reference to the function, timerFunction to setTimeout. The first example, passes the result of timerFunction() to setTimeout.
I'm in a bit of a pickle with this one. I'm using jQuery DataTables 1.10.6, and I want to make it so that when the user stops typing (like maybe after 950 ms?), the search is performed. I kind of have it working, but since I'm using server-side processing, sSearch (the search parameter) returns null.
I'm guessing it has to do with the unbinding and re-binding, but I don't know how to make it so that sSearch is sent properly.
var delay = function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
}
})();
$("div.dataTables_filter input").unbind();
$("div.dataTables_filter input").bind("keyup", function () {
alert(this.value);
delay(function () {
$("#MyTable").dataTable().fnFilter(this.value);}, 1000);
}
DataTables has an option to se delay, you can check it here
I found a deprecated plugin which is a key debounce delay: https://www.datatables.net/plug-ins/api/fnSetFilteringDelay
Even though it's stated that this won't work with 1.10+, there's a comment stating that a line change would allow it to work in 1.10+. So the following line:
anControl.unbind('keyup search input').bind('keyup search input', function() {
...would be replaced with:
anControl.off('keyup search input').on('keyup search input', function() {
I was also able to set the filtering delay timer in the calling argument. Works like a charm.
Any ideas how to extend the step-function in jQuery 1.6+?
I've made a special-event to trigger a custom-event on each animated step. However since jQuery's animation method was changed, or rather the step function is not longer extendable ($.fx.step results in an empty object) is it impossible to extend it with your own things.
(function($){
var oldStep = $.fx.step._default;
$.event.special.animating = { };
$.fx.step._default = function( fx ) {
$(fx.elem).trigger('animating', fx);
oldStep.apply( this, arguments );
};
}(jQuery));
$('#foo').animate({width: 200});
$('#foo').bind('animating', function(e, fx){
console.log(fx);
});
Any ideas how to get this to work with newer jQuery versions?
Got it, in jQuery's updates-blog, this is already flagged to be commented.
QA just filed a real doozy of a bug, and I'm scratching my head how to fix it.
If two buttons, e.g. back, and search are pressed at the same time, each will invoke Ext.dispatch, causing two simultaneous opposing transitions! This totally !##$s up the layout, rendering the app unusable.
This is really a general problem with touch-enabled apps... with multiple fingers hovering over the screen, the user can easily trigger weird and totally incompatible action combinations, and the app needs to accept only one at a time. Is there any way to handle this situation gracefully in Sencha Touch?
I fixed it by listening to the before-dispatch event, and canceling it if there is a dispatch already in progress.
Ext.regApplication(...
this._isDispatching = false,
launch: function() {
Ext.Dispatcher.on('before-dispatch', function () {
var me;
if (this._isDispatching)
return false;
else {
this._isDispatching = true;
me = this;
setTimeout(function () {
me._isDispatching = false;
}, 500);
return true;
}
}, this);
}
Yes, the 500ms delay is definitely hacky, but I couldn't think of a more robust way of detecting when the transition has completed. There is no after-dispatch event, and the dispatch event fires before the transition has completed.
Hope this helps someone.