Skip to content

Instantly share code, notes, and snippets.

@theadam
Created July 21, 2016 20:34
Show Gist options
  • Save theadam/0417b9e27e3ef0ad1111c88149d53a7c to your computer and use it in GitHub Desktop.
Save theadam/0417b9e27e3ef0ad1111c88149d53a7c to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<div id="app"></div>
</body>
</html>
/** @jsx h */
import { render } from 'preact';
import { h } from 'preact-flyd';
//import { render } from 'react-dom';
//import { h } from 'react-flyd';
import { stream, scan, merge} from 'flyd';
let items$ = stream([1,2,3,4,5,])
function List() {
return (
<div>
<div>
<button id="plus" onClick={e => items$(items$().concat(Math.random()))}>+</button>
</div>
{items$.map(items => items.length % 2 === 1 ?
<ul>
{items.map(item => <li key={item}>{item}</li>)}
</ul> :
null
)}
</div>
);
}
render(<List />, document.getElementById('app'));
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"preact": "5.4.0",
"preact-flyd": "0.0.4",
"flyd": "0.2.2"
}
}
'use strict';
var _preact = require('preact');
var _preactFlyd = require('preact-flyd');
var _flyd = require('flyd');
var items$ = (0, _flyd.stream)([1, 2, 3, 4, 5]);
//import { render } from 'react-dom';
//import { h } from 'react-flyd';
/** @jsx h */
function List() {
return (0, _preactFlyd.h)(
'div',
null,
(0, _preactFlyd.h)(
'div',
null,
(0, _preactFlyd.h)(
'button',
{ id: 'plus', onClick: function onClick(e) {
return items$(items$().concat(Math.random()));
} },
'+'
)
),
items$.map(function (items) {
return items.length % 2 === 1 ? (0, _preactFlyd.h)(
'ul',
null,
items.map(function (item) {
return (0, _preactFlyd.h)(
'li',
{ key: item },
item
);
})
) : null;
})
);
}
(0, _preact.render)((0, _preactFlyd.h)(List, null), document.getElementById('app'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment