(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
/** | |
* Takes a function a lazily runs it once when invoked. | |
* | |
* Returns cached return value to subsequent calls. | |
* Return value will always have reference equality with subsequent calls. | |
* | |
* @param {function} func - Function to run Once | |
* @return {function} | |
*/ | |
export default function once(func) { |
import { debounce } from 'lodash'; | |
class ResizeObservable { | |
constructor() { | |
this.listeners = []; | |
this._resizeFunc = debounce(() => { | |
this.emit(); | |
}, 300); |
/** | |
* Inserts a script tag of src | |
* in the Head of HTML. | |
* | |
* @param {string} src - Src for Javascript request | |
* @param {Object} config | |
* @return {Promise} - Returns a promise of event when loaded / error | |
*/ | |
export default function insertScript(src, { async = true, defer = false } = {}) { | |
return new Promise((resolve, reject) => { |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
const noop = () => {}; | |
/** | |
* This Class creates a Promise object | |
* that has its resolve and reject | |
* methods publicly exposed. | |
* | |
* This allows a user to resolve / reject | |
* this promise from outside the Promise function scope. | |
*/ |
import fs from 'fs'; | |
/** | |
* Returns a Promise from createReadStream pipe. | |
* Resolves Promise when end of data event fires. | |
* Rejects Promise when error occurs in stream. | |
* | |
* @param {String} filePath - File Path to create readable stream from | |
* @param {Stream} writableStream - Writable Stream to write to |
/* Import in React Project files */ | |
import React, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { Provider } from 'react-redux'; | |
import thunk from 'redux-thunk'; | |
import { combineReducers, compose, applyMiddleware, createStore } from 'redux'; | |
import { persistStore, autoRehydrate } from 'redux-persist'; | |
import localForage from 'localforage'; | |
/* Import Routes and App Data */ |
import React, { PropTypes, Component } from 'react'; | |
class BouncePress extends Component { | |
constructor(props) { | |
super(props); | |
this.bouncePressElem = null; | |
} | |
addBouncePressRef = (e) => { | |
this.bouncePressElem = e; |
import React, { Component, PropTypes } from 'react'; | |
import { LoadingSplash, LoadingSpinner } from 'components/Injectables'; | |
export default class LazyLoad extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
loading: true, | |
error: '', |
{ | |
"AL": "Alabama", | |
"AK": "Alaska", | |
"AS": "American Samoa", | |
"AZ": "Arizona", | |
"AR": "Arkansas", | |
"CA": "California", | |
"CO": "Colorado", | |
"CT": "Connecticut", | |
"DE": "Delaware", |