Playing with Node.js Event Loop

setImmediate/clearImmediate - will execute code at the end of the current event loop cycle process.nextTick - used to schedule a callback function to be invoked in the next iteration of the Event Loop function cb(msg){ console.log(msg); } setImmediate(cb, 'setImmediate'); process.nextTick(cb, 'process.nextTick: 1'); process.nextTick(cb, 'process.nextTick: 2'); process.nextTick(cb, 'process.nextTick: 3'); console.log('Processed in the first iteration'); process.nextTick(cb, 'process.nextTick: 4'); process.nextTick(cb, 'process.nextTick: 5'); Output: Processed in the first iteration process.nextTick: 1 process.nextTick: 2 process.nextTick: 3 process.

by lek tin in "programming" access_time 1-min read

Conditional Render in React

In react, sometimes we need to render a component based on some flag, for example, we need to display a different set of information to the admin users than the normal users. We have a prop called isAdmin render () { const { isAdmin } = this.props return ( <div> { isAdmin ? <CustomeComponent {...propSetA} / > : <CustomeComponent {...propSetB} / > } </div> ) } Looks good right, but there is one problem.

by lek tin in "javascript" access_time 1-min read