Skip to content

Instantly share code, notes, and snippets.

@timwis
timwis / index.js
Created August 6, 2016 15:25
requirebin sketch
var html = require('bel')
var morphdom = require('morphdom')
var saved
function child () {
saved = saved || html`<h1 onload=${() => console.log('child on')} onunload=${() => console.log('child off')}>child</h1>`
return saved
}
function parent () {
@timwis
timwis / index.js
Created July 26, 2016 23:18
requirebin sketch
const choo = require('choo')
const html = require('choo/html')
const app = choo()
app.model({
state: {
convos: {
'2151234567': generateItems(50),
'9891239876': generateItems(50),
var list = document.querySelector('#filter-list ul')
var listItems = Array.from(list.children)
var depts = listItems.map((li) => {
var link = li.querySelector('.content-department')
return link.innerText + "\t" + link.getAttribute('href')
})
copy(depts.join("\n"))
@timwis
timwis / index.js
Created July 22, 2016 10:33
requirebin sketch
const choo = require('choo')
const html = require('choo/html')
const http = require('choo/http')
const app = choo()
app.model({
effects: {
fetch: (data, state, send, done) => {
send('sub', (err) => {
if (err) {
@timwis
timwis / index.js
Created July 21, 2016 10:59
requirebin sketch
const yo = require('yo-yo')
function parent (title) {
return yo`<div>${child(title)}</div>`
}
function child (title) {
const el = yo`<h1>${title}</h1>`
window.setTimeout(() => {
// silly example, but really referring to L.map() or other init() libraries
@timwis
timwis / form.js
Created July 16, 2016 21:00
choo form component example
const getFormData = require('get-form-data')
const html = require('choo/html')
module.exports = function formComponent (opts) {
return `
<form>
<input name="woof" type="text" placeholder="type here"
value=${opts.values.woof} oninput=${onInput}>
<input type="submit" onsubmit=${onSubmit}>
</form>
function formatDate (iso) {
const [year, month, day] = iso.split('T')[0].split('-')
return `${+month}/${+day}/${year}`
}
@timwis
timwis / index.js
Created July 8, 2016 00:21
requirebin sketch
const choo = require('choo')
const html = require('choo/html')
const app = choo()
app.model({
state: {
title: 'Hello'
},
reducers: {
update: (data, state) => ({ title: data })
@timwis
timwis / index.js
Created June 30, 2016 10:05
requirebin sketch
var onload = require('on-load')
var yo = require('yo-yo')
function page1 () {
var tree = yo`<div>page1</div>`
onload(tree, function () {
console.log('page1 on')
}, function () {
console.log('page1 off')
})
app.router((route) => [
route('/', layouts.root(views.connect)),
route('/tables', layouts.root(layouts.database()), [
route('/:name', layouts.root(layouts.database(views.tableRows, 'rows')), [
route('/schema', layouts.root(layouts.database(views.tableSchema, 'schema'))),
route('/options', layouts.root(layouts.database(views.tableOptions, 'options')))
])
])
])