var elements = query`.${className}`;var message = l10n`Hello ${name}; you are visitor number ${visitor}:n!| # to generate your dhparam.pem file, run in the terminal | |
| openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
| // this is now a module: | |
| // https://github.com/WebReflection/backtick-template#es2015-backticks-for-es3-engines-- | |
| var template = require('backtick-template'); | |
| // just string | |
| const info = 'template'; | |
| `some ${info}` === template('some ${info}', {info}); |
| var RecursiveChildComponent = React.createClass({ | |
| render() { | |
| return <div> | |
| {this.recursiveCloneChildren(this.props.children)} | |
| </div> | |
| }, | |
| recursiveCloneChildren(children) { | |
| return React.Children.map(children, child => { | |
| if(!_.isObject(child)) return child; | |
| var childProps = {someNew: "propToAdd"}; |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent| // The classic AJAX call - dispatch before the request, and after it comes back | |
| function myThunkActionCreator(someValue) { | |
| return (dispatch, getState) => { | |
| dispatch({type : "REQUEST_STARTED"}); | |
| myAjaxLib.post("/someEndpoint", {data : someValue}) | |
| .then( | |
| response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}), | |
| error => dispatch({type : "REQUEST_FAILED", error : error}) | |
| ); |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.
| const timing = store => next => action => { | |
| performance.mark(`${action.type}_start`); | |
| let result = next(action); | |
| performance.mark(`${action.type}_end`); | |
| performance.measure( | |
| `${action.type}`, | |
| `${action.type}_start`, | |
| `${action.type}_end` | |
| ); | |
| return result; |