made with esnextbin
Last active
April 9, 2016 02:58
-
-
Save davidchase/cd5fbfb2862d50f2749e740fdbc7ecfc to your computer and use it in GitHub Desktop.
esnextbin sketch
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"/> | |
</head> | |
<body> | |
<button>Click Me</button> | |
</body> | |
</html> |
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 { empty, fromEvent, fromPromise, just, continueWith} from 'most' | |
import {delay} from 'creed'; | |
const apiEndpoint = 'http://jsonplaceholder.typicode.com/posts/1' | |
function makeApiCall(){ | |
return fetch(apiEndpoint).then(resp => resp.json()); | |
}; | |
const s = fromEvent('click', document.querySelector('button')) | |
.map(makeApiCall) | |
.await() | |
.take(1) | |
const c = s.continueWith(() => s); | |
s.continueWith(() => c) | |
.observe(console.log.bind(console)) |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"most": "0.18.8", | |
"creed": "1.0.1" | |
} | |
} |
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
'use strict'; | |
var _most = require('most'); | |
var _creed = require('creed'); | |
var apiEndpoint = 'http://jsonplaceholder.typicode.com/posts/1'; | |
function makeApiCall() { | |
return fetch(apiEndpoint).then(function (resp) { | |
return resp.json(); | |
}); | |
}; | |
var s = (0, _most.fromEvent)('click', document.querySelector('button')).map(makeApiCall).await().take(1); | |
var c = s.continueWith(function () { | |
return s; | |
}); | |
s.continueWith(function () { | |
return c; | |
}).observe(console.log.bind(console)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment