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 _if(truthy, then) { | |
[then, function () {}][+!truthy](); | |
} | |
function ifElse(truthy, then, _else) { | |
[then, _else][+!truthy](); | |
} | |
function and(a, b) { | |
return !!((!!a + !!b) >> 1); |
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 { loop, Effects as E, liftState } from "redux-loop" | |
import { | |
cond, pathEq, map, T, reduce, toUpper, pipe, transpose, | |
lensProp, set as lensSet, view as lensView | |
} from "ramda" | |
export const mkInit = (f) => pipe(f, liftState) | |
export const mkActionType = (namespace) => (type) => `${namespace}/${type}` |
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
// Require hook | |
function hook(compile, extension) { | |
require.extensions[extension] = function(m, filename) { | |
const tokens = compile(filename); | |
return m._compile('module.exports = ' + JSON.stringify(tokens), filename); | |
}; | |
} | |
// Run require hook | |
hook(fetch, '.css'); |
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
// Auto restart server on file changes | |
(function () { | |
var fs = require('fs'), | |
original = require.extensions['.js']; | |
function exitOnChange(filename) { | |
fs.watchFile(filename, function (curr, prev) { | |
if (curr.mtime !== prev.mtime) { | |
process.exit(); | |
} |
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
// Observable to Promise | |
var promise = Rx.Observable.return(42).toPromise(RSVP.Promise); | |
promise.then(console.log.bind(console)); | |
// => 42 | |
// Using config instead of argument | |
Rx.config.Promise = RSVP.Promise; | |
var promise = Rx.Observable.return(42).toPromise(); | |
promise.then(console.log.bind(console)); | |
// => 42 |
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 Rx = require("rx"); | |
/** | |
* Using rxjs's fork join to wait for multiple remote ajax calls | |
*/ | |
var remoteData = Rx.Observable.forkJoin( | |
Rx.Observable.fromPromise($.get('/api/product/list')), | |
Rx.Observable.fromPromise($.get('/api/channels/list')), | |
Rx.Observable.fromPromise($.get('/api/entity/list/PERSONNEL')) |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Parallel AJAX</title> | |
<style> | |
body { | |
font-family: Arial; |
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
let everythingIsDone = Rx.Observable.fromEvent(em, ‘everythingIsDone’); | |
let eventSource = Rx.Observable.fromEvent(em, ‘event’).takeUntil(everythingIsDone).toArray().toPromise(); |
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 _ = require('lodash'); | |
var github = require('octonode'); | |
var Rx = require('rx'); | |
// repos :: Search -> Options -> Observable Data | |
// callback style is converted to Promise and then to Observable | |
function repos(search, options) { | |
return Rx.Observable.fromPromise(new Promise(function (resolve, reject) { | |
search.repos(options, function (err, body, header) { |
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 source = Rx.Observable.fromArray([1,2,3]) | |
.flatMap(async function (x, i) { | |
var result = await Promise.resolve(x * i); | |
return result; | |
}); | |
source.subscribe(function (x) { console.log(x); }); |
OlderNewer