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
var isBrowserOld = ! Function.prototype.bind; | |
// Can also add an CSS class | |
document.documentElement.className += ' old-browser'; |
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 _ from 'lodash'; | |
function makeStatic(data) { | |
return Promise.all(_.map(data, function map(v, k) { | |
if (v instanceof Promise) { | |
return v.then(x => x, () => null) | |
.then(data => [k, data]); | |
} | |
return [k, v]; |
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 _ from 'lodash'; | |
export function enumNumber(... params) { | |
return Object.freeze(_.mapValues(_.invert(params), Number)); | |
} | |
export function enumString(... params) { | |
return Object.freeze(_.mapKeys(params)); | |
} |
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 storeDecorator from './store-decorator'; | |
import someStore, { SOME_STORE_SYMBOL } from './some-reflux-store'; | |
@storeDecorator(someStore) | |
class SomeComponent extends Component { | |
render() { | |
return ( | |
<div> | |
{this.state[SOME_STORE_SYMBOL].someProperty} |
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 Ember from 'ember'; | |
var volatileValue = 0; | |
export default Ember.Controller.extend({ | |
init() { | |
this._super(...arguments); | |
Ember.run.later(this, function interval() { | |
this.incrementProperty("timer"); | |
console.log(this.get("value")); |
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 Rx from "rxjs/Rx"; | |
import cycleRun from "./mini-cycle"; | |
function loggerDriver(source$) { | |
source$.subscribe((text) => console.log(text)); | |
return Rx.Observable.empty(); | |
} |
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
var nicerNoop = new Proxy(function() {}, { | |
get() { | |
return nicerNoop; | |
}, | |
apply() { | |
return nicerNoop; | |
}, | |
construct() { |
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 as ReactComponent} from "react"; | |
export function makeRafDelayed(Component) { | |
return class RafDelayedComponent extends ReactComponent { | |
state = { | |
isFirstRender: true, | |
}; | |
componentDidMount() { | |
this.setState({ |
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
// Source #1: http://ideasintosoftware.com/typescript-advanced-tricks/ | |
// Source #2: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-308052919 | |
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; | |
type Omit<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]}; | |
// Example: type TCleanedUser = Omit<IUser, 'privateField1' | 'privateField2'>; |
OlderNewer