This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const moment = require('moment'); | |
const PERIOD = moment.duration(3, 'days'); | |
module.exports = { | |
PERIOD, | |
isWithinPeriod(test) { | |
return moment().add(PERIOD).isAfter(test); | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// skip the first two args as they are node and this script | |
const [,,filepath] = process.argv; | |
doSomethingFSLike(filepath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
topLevel: { | |
intermediate, // declaration of intermediate | |
intermediate: { | |
nested // declaration of nested | |
} | |
} | |
} = { | |
topLevel: { | |
intermediate: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function defaults({ a = 1, b = 2 } = {}) { | |
console.log('a', a); | |
console.log('b', b); | |
} | |
defaults(); | |
// a 1 | |
// b 2 | |
defaults({ a: 42, b: 32 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function defaults({ a, b } = { a: 1, b: 2 }) { | |
console.log('a', a); | |
console.log('b', b); | |
} | |
defaults(); | |
// a 1 | |
// b 2 | |
defaults({ a: 42, b: 32 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple renaming to avoid collisions or just as a preference. | |
const a = 5; | |
const { a: b } = { a: 3 }; | |
console.log(b); // prints 3 | |
// rename for another API and use enhanced object literal notation. | |
function verifyUser({ userId: id }) { | |
return User.update({ id, verified: true }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// can destructure arrays | |
const [a, b] = [1,2]; // a = 1, b = 2 | |
// can destructure object keys | |
const { a } = { a: 3 }; // a = 3 | |
// even function parameters | |
function foo({ a }) { | |
console.log(a); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { SubWidgetLink } from './routes' | |
export default class MyComponentWithALink extends Component { | |
render() { | |
const { widget } = this.props | |
return ( | |
<div> | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { combineReducers } from 'redux' | |
import { createAction, handleActions } from 'redux-actions' | |
const authorFetched = createAction('AUTHOR_FETCHED') | |
const bookFetched = createAction('BOOK_FETCHED') | |
const authorReducer = handleActions({ | |
AUTHOR_FETCHED: (state, action) => { | |
const author = action.payload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { combineReducers } from 'redux' | |
import { createAction, handleActions } from 'redux-actions' | |
const authorFetched = createAction('AUTHOR_FETCHED') | |
const bookFetched = createAction('BOOK_FETCHED') | |
const literaryReducer = handleActions({ | |
// maybe an author has a bunch of books as sub-resources | |
AUTHOR_FETCHED: (state, action) => { | |
const author = action.payload |