Skip to content

Instantly share code, notes, and snippets.

View serebano's full-sized avatar

Sergiu Toderascu serebano

View GitHub Profile
/** @jsx h */
import ReactDOM from "react-dom"
export const Count = [
({ state, props }) => ({ value: state.count(Number), color: props.color }),
({ value, color }, h) => <h2 style={{ color, margin: 0 }}>{value}</h2>
]
export default [
// 1
window.print = function print(json) {
if (typeof json != "string") {
json = JSON.stringify(json, undefined, "\t")
}
var arr = [],
_string = "color:green",
_number = "color:darkorange",
_boolean = "color:blue",
_null = "color:magenta",
data = {
state: {
users: {
foo: {name: 'Foo'}
}
}
}
tree = {
state: new Model(data, 'state'),
class Model {
constructor(tree, path) {
this.path = path ? path.split(".") : []
this.tree = tree ? tree : {}
this.changes = []
}
get(path) {
return this.path.concat(path.split(".")).reduce((o,k) => o && o[k], this.tree)
}
set(path, value) {
class Tag {
static isTag(arg) {
return arg instanceof Tag
}
static create(type) {
return (keys, ...values) => new Tag(type, keys, values)
}
@serebano
serebano / funbox.js
Last active November 20, 2016 05:16
funbox
function funbox(reducer) {
const box = ctx => box.run(ctx)
box.use = (...functions) => {
box.index = (box.index||[]).concat(...functions)
box.run = ctx => box.index.reduce(reducer, ctx)
}
return box
}
const app = funbox((ctx, fun) => {
@serebano
serebano / fun.js
Created October 30, 2016 16:10
JS Middleware Fun
/** fun.js
JS Middleware Fun
num = fun((n, next) => 10 + next(n * 1))
.use((n, next) => 20 - next(n - 2))
.use((n, next) => 30 * next(n / 3))
num(1)
*/
export default(...stack) => {
@serebano
serebano / inc.jsx
Last active November 19, 2016 18:06
var data = {
count: 0
}
function onClick() {
data.count++
render()
}
function render() {
@serebano
serebano / hi.js
Last active December 30, 2015 10:01
hi!box
<hi(props, name) export>
<h1 => 'Hello ', this.name || String(name)
<input on-input=(e => this.pub('name', e.target.value)) />
<style +scoped>
:scope {
display: block;
font-family: Helvetica Neue;
font-size: 16px;
color: ${ box.color(props.color) };
}
<link rel="import" href="../google-map/google-map.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;