This file contains hidden or 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 {Component, PropTypes} from 'react'; | |
| import getMuiTheme from './getMuiTheme'; | |
| class MuiThemeProvider extends Component { | |
| static propTypes = { | |
| children: PropTypes.element, | |
| muiTheme: PropTypes.object, | |
| }; |
This file contains hidden or 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
| export default class Provider extends Component { | |
| getChildContext() { | |
| return { store: this.store } | |
| } | |
| constructor(props, context) { | |
| super(props, context) | |
| this.store = props.store | |
| } |
This file contains hidden or 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
| class App extends React.Component{ | |
| render = () => <div className="app">{this.props.children}</div> | |
| } | |
| class Greeting extends React.Component{ | |
| render = () => <p style={this.context.style}>Hello world!</p> | |
| } | |
| Greeting.contextTypes = { | |
| color: React.PropTypes.string, | |
| backgroundColor: React.PropTypes.string | |
| } |
This file contains hidden or 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 asyncToReact(fn) { | |
| class PromiseComponent extends React.Component { | |
| state = { waiting: true, result: null }; | |
| componentDidMount() { | |
| fn(...this.props.args).then(result => this.setState({ waiting: false, result })); | |
| } | |
| componentDidUpdate() { | |
| fn(...this.props.args).then(result => this.setState({ waiting: false, result })); | |
| } | |
| shouldComponentUpdate(newProps) { |
This file contains hidden or 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
| var debugMode=false; | |
| //..... | |
| function logMessage() { | |
| if(!debugMode) return; | |
| console.log(Array.prototype.slice.call(arguments) ); | |
| } |
This file contains hidden or 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 assert = require('assert') | |
| const identity = a => a | |
| const add = a => b => b + a | |
| const call = a => b => b(a) | |
| const multiple = a => b => b%a === 0 | |
| const get = a => b => b[a] | |
| const desc = (a, b) => b-a | |
| const makeArray = (start, end) => |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"/> | |
| <title>array augmenting: push read vs concat</title> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
| <script src="./suite.js"></script> | |
| </head> | |
| <body> | |
| <h1>Open the console to view the results</h1> |
This file contains hidden or 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
| // where `db` is a `Firebase` ref | |
| export function checkIfUserExists(authData) { | |
| return db | |
| .child('users') | |
| .child(authData.uid) | |
| .once('value') | |
| .then(dataSnapshot => { | |
| return Promise.resolve({ | |
| authData, |
This file contains hidden or 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
| // 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}) | |
| ); |
This file contains hidden or 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 users = [{userId:"34"},{userId: "10"}, {userId: "1"}, {userId: "1"}] | |
| const sameUserId = (a, i) => (b, j) => a.userId === b.userId && j>i | |
| users.filter((value, index, array) => array.findIndex(sameUserId(value, index)) < 0) |