Skip to content

Instantly share code, notes, and snippets.

@davidchase
Last active April 9, 2016 02:58
Show Gist options
  • Save davidchase/cd5fbfb2862d50f2749e740fdbc7ecfc to your computer and use it in GitHub Desktop.
Save davidchase/cd5fbfb2862d50f2749e740fdbc7ecfc to your computer and use it in GitHub Desktop.
esnextbin sketch
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<button>Click Me</button>
</body>
</html>
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))
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"most": "0.18.8",
"creed": "1.0.1"
}
}
'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