settimeout

Angular 2 detectChanges vs setTimeout()

帅比萌擦擦* 提交于 2019-12-11 07:33:21
问题 I'm facing an issue regarding angular 2 change detection. I'm using a component which uses the 'onPush' strategy and I've noticed that it's child component don't update them self on update (They themselves also 'onPush') so I've added changeDetector.detectChanges() to my code and it caused Maximum call stack size exceeded . I dag up a little bit and wound up doing setTimeout(() => { this.changeDetector.markForCheck(); }, 0); And the code worked just fine. My question is why angular

Update, exit, update, enter patterns with transition

半城伤御伤魂 提交于 2019-12-11 06:48:47
问题 Essentially, according to this bl.ocks, I am trying to have all the blocks go to 0 before starting a new sequence. I think what I require is the following sequence: Update to 0 Exit to 0 Update random number Enter with new number I have tried to follow the pattern above by adding the following code block: function update(n1) { var cellUpdate = cell.selectAll("rect") .data(d3.range(0)); var n0 = cell.selectAll("rect").size(); var cellExit = cellUpdate.exit().transition() .delay(function(d, i)

how to Randomly rotate images javascript?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 06:23:49
问题 how do i randomly rotate the images without refreshing the page with setTimeout?? js: var bannerImages = new Array( ); bannerImages[0] = "Banner1.jpg"; bannerImages[1] = "Banner2.jpg"; bannerImages[2] = "Banner3.jpg"; bannerImages[3] = "Banner4.jpg"; var randomImageIndex = Math.round( Math.random( ) * 3 ); document.write( "<img alt=\"\" src=\"imgs/" + bannerImages[randomImageIndex] + "\">" ); ` 回答1: Just change the src attribute of the image: <img id="pic" src="http://jsfiddle.net/favicon.png

Stopping Nested Timeouts in Javascript

…衆ロ難τιáo~ 提交于 2019-12-11 06:19:02
问题 I want to execute a piece of arbitrary code and be able to stop it whenever I want. I figured I could do this with setTimeout and then use clearTimeout to stop it. However if the code in the timeout creates it's own timeouts, then those keep executing even after I clear the original. Example: var timeoutID = setTimeout( function(){ console.log("first event can be stopped with clearTimout(timeoutID)"); setTimeout(function(){console.log("but not this one")}, 5000) }, 5000) Now one way would be

setInterval() to add class then remove class for same amount of time

若如初见. 提交于 2019-12-11 06:06:54
问题 I am trying to make a simple 'Simon Game'. I am currently stuck trying to add a class 'on' to a div for one second, then remove that class for the same amount of time. So I have four divs that I am blinking on and off depending on a sequence of numbers, e.g. [0, 1, 2, 3] . This would blink div[0] on for one second and off for one second then move to div[1] , on and off and so on. Here is my function /** * sequence => array [0, 1, 2, 3] * speed => int 1000 (one second) */ playSequence:

Wait till all items from mongoDB query are processed before continuing

梦想的初衷 提交于 2019-12-11 05:36:05
问题 I'm working on a pretty complex project where a lot of mongoDB queries have to be processed in order to show data. Right now, when performing a query over a big set of data, not all data shows as soon as the page loads. For now I fixed that problem by setting a timeout function, before using the next() function. So this is where one of the functions is called: router.get('/playwall', account.checkSession, playwalls.get, function(req, res, next) { res.render('dashboard/playwalls/index'); });

setTimeout don't working with function return Promise

别来无恙 提交于 2019-12-11 04:19:59
问题 Here is my code: exports.test = function() { x(1) } var x = function(no) { var client = new twitter({ consumer_key: global.twitter_consumer_key, consumer_secret: global.twitter_consumer_secret, access_token_key: 'token key', access_token_secret: 'token key' }); var link_user_show = 'https://api.twitter.com/1.1/users/show.json?screen_name=' + 'mahdi_almayali' + '&user_id=' client.get(link_user_show, function(err, data) { if (err) { console.log('err at check_twitter_username: ', err) // reject

Avoid forced delay of setTimeout when breaking up long running JavaScript tasks

谁都会走 提交于 2019-12-11 04:14:29
问题 I have a long running task in JavaScript, which I break up in chunks with a series of nested setTimeout(processChunk, 0) , similar to what is described here. However, for each invocation, setTimeout adds an additional delay of 4 ms or more. This behaviour is well known and varies across browsers. When I attempt to keep the processing time of each chunk at 50 ms or less, these additional delays increase total processing time by at least 10%. My question is : Can I avoid the additional delay

Understanding JavaScript setTimeout and setInterval

ぐ巨炮叔叔 提交于 2019-12-11 03:20:18
问题 I need a bit of help understanding and learning how to control these functions to do what I intend for them to do So basically I'm coming from a Java background and diving into JavaScript with a "Pong game" project. I have managed to get the game running with setInteval calling my main game loop every 20ms, so that's all ok. However I'm trying to implement a "countdown-to-begin-round" type of feature that basically makes a hidden div visible between rounds, sets it's innerHTML = "3" // then

setTimeout calling function inside function - Scope-Issue

依然范特西╮ 提交于 2019-12-11 03:14:27
问题 So, the problem is that I have a function inside a function that needs to be called by setTimeout. That doesn't work however because setTimeout will assume that the function it calls has the root as its' scope. Any idea how I could solve this without changing the scope of the function? Edit: Here is what I mean: function general(){ function saysomething(){ console.log('hi there'); } setTimeout("saysomething();", 1000); } The setTimeout fails.. 回答1: function general(){ function saysomething(){