(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.
// This is an example of how to fetch external data in response to updated props, | |
// If you are using an async mechanism that does not support cancellation (e.g. a Promise). | |
class ExampleComponent extends React.Component { | |
_currentId = null; | |
state = { | |
externalData: null | |
}; |
declare module 'fs-extra' { | |
import type { | |
createReadStream as createReadStreamType, | |
createWriteStream as createWriteStreamType, | |
} from 'fs' | |
declare export var createReadStream: $PropertyType< | |
$Exports<'fs'>, | |
'createReadStream', | |
> |
let cache = new Map(); | |
let pending = new Map(); | |
function fetchTextSync(url) { | |
if (cache.has(url)) { | |
return cache.get(url); | |
} | |
if (pending.has(url)) { | |
throw pending.get(url); | |
} |
// Below are some useful Flow utility type functions, some I've written and some I've found on the web. | |
// All contributions welcome! | |
// Extracting a data type from a maybe type, e.g. getting `string` from `?string` | |
type _ExtractFromMaybe<T, M: ?T> = T | |
export type ExtractFromMaybe<M> = _ExtractFromMaybe<*, M> | |
// FROM https://hackernoon.com/redux-flow-type-getting-the-maximum-benefit-from-the-fewest-key-strokes-5c006c54ec87 | |
// Extracting the type of a function's return value | |
type _ExtractReturn<R, F: (...args: any[]) => R> = R |
// a modification from http://goo.gl/tLbLXr | |
var attachEvent = function(element, event, fn) { | |
if (element.addEventListener) | |
element.addEventListener(event, fn, false); | |
else if (element.attachEvent) // if IE | |
element.attachEvent('on' + event, fn); | |
} | |
var onReady = function(func) { |
(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.
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>jQuery Animate() Step Demo</title> | |
<script type="text/javascript" src="../jquery-1.4.1.js"></script> | |
<script type="text/javascript"> | |
// When the DOM is ready, initialize. | |
jQuery(function( $ ){ |
var __slice = Array.prototype.slice; | |
(function($) { | |
var Sketch; | |
$.fn.sketch = function() { | |
var args, key, sketch; | |
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | |
if (this.length > 1) { | |
$.error('Sketch.js can only be called on one element at a time.'); | |
} | |
sketch = this.data('sketch'); |
( function( window, undefined ) { | |
'use strict'; | |
// helper function | |
function capitalize( str ) { | |
return str.charAt(0).toUpperCase() + str.slice(1); | |
} | |
// ========================= getStyleProperty by kangax =============================== |
/* | |
THIS GIST IS OUT OF DATE AND NOT MONITORED | |
PLEASE SEE https://github.com/leecrossley/cordova-plugin-shake-detection | |
*/ | |
var shake = (function () { | |
var shake = {}, | |
watchId = null, | |
options = { frequency: 300 }, | |
previousAcceleration = { x: null, y: null, z: null }, |