What is npm-shrinkwrap ?

Apr 26, 2017

npm-shrinkwrap command locks down the versions of a package’s dependencies so that you can control exactly which versions of each dependency will be used when your package is installed.

References

  • https://docs.npmjs.com/cli/shrinkwrap
Categories : NodeJS   JavaScript

ES6 Spread Syntax

Apr 26, 2017

The spread syntax allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignments) are expected.

Spread syntax can be only applied to iterable objects.

Rest syntax looks exactly like spread syntax. In a way, rest syntax is the opposite of spread syntax. Spread syntax “expands” an array into its elements, while rest syntax collects multiple elements and “condenses” them into a single element.

function sum(a, b) {
    return a+b;
}

const args = [1, 2];

let result = sum(...args); 
console.log(result); // 3
const arr = [1, 2, 3];
const arrCopy = [...arr]; 
console.log(arrCopy); // [1, 2, 3]

References

Categories : ES6   JavaScript

What is a React Pure Component ?

Apr 25, 2017

If React components render() function renders the same result given the same props and state , you can use PureComponent for a performance boost.

PureComponent’s shouldComponentUpdate() function only shallow compares the objects. Also its skips prop updates for the whole component subtree. So need to make sure that all the children components are also “pure”.

Best use case for PureComponent are presentational components which have no child components and no dependencies on the global state in the application.

class MyComponent extends React.PureComponent {
    render() {
        return (
            <h1>Hello World!</h1>
        );
    }
}

References

Categories : React   JavaScript

What is a Test Fixture ?

Apr 24, 2017

A test fixture is a fixed state of a set of objects used as a baseline for running tests. The purpose of test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.

References

  • https://github.com/junit-team/junit4/wiki/test-fixtures
Categories : Testing

Duck Typing in JavaScript ?

Apr 13, 2017

The term duck typing comes from the saying “If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck”.

Duck Typing helps to avoid conditional in JavaScript. Duck Typing helps to emulate interface interfaces in JavaScript.

References

  • http://adripofjavascript.com/blog/drips/using-duck-typing-to-avoid-conditionals-in-javascript.html
  • http://jscriptpatterns.blogspot.com/2013/01/javascript-interfaces.html
  • https://en.wikipedia.org/wiki/Duck_typing
Categories : JavaScript