Skip to content

Instantly share code, notes, and snippets.

View nickbalestra's full-sized avatar

Nick Balestra-Foster nickbalestra

View GitHub Profile
@nickbalestra
nickbalestra / IstantiationPatternsTest.html
Last active August 29, 2015 14:24
Istantiation Patterns - Performance Test
<html>
<head>
<meta charset="UTF-8">
<title>Istantation Patterns Permormance Test</title>
<script src="functional.js"></script>
<script src="functionalShared.js"></script>
<script src="protototypal.js"></script>
<script src="pseudoclassical.js"></script>
</head>
<body>
@nickbalestra
nickbalestra / recursiveReduce.js
Last active October 2, 2015 03:01
Recursive reduce --es6 tail call optmized
// Recursive implementation of reduce
// Supports ES6 interpreter Tail Call Optimization
// http://www.ecma-international.org/ecma-262/6.0/#sec-tail-position-calls
// https://kangax.github.io/compat-table/es6/#test-proper_tail_calls_(tail_call_optimisation)
function recursiveReduce(list, callback, accumulator) {
if (list.length === 0) return accumulator;
accumulator === undefined ?
accumulator = list[0] :
@nickbalestra
nickbalestra / recursiveEach.js
Last active October 9, 2015 00:53
Recursive Reduce and Each
function recursiveEach(list, iterator) {
if (list.length === 0) {
return undefined;
}
iterator(list[0]);
return recursiveEach(list.slice(1), iterator);
};
@nickbalestra
nickbalestra / main.js
Created October 5, 2016 23:10
cycleFizz
import xs from 'xstream';
import { run } from '@cycle/xstream-run';
import { makeDOMDriver, div, button, h1 } from '@cycle/dom';
const fizzBuzz = (n, result='') => {
if (n === 0) return result;
if (n % 3 === 0) result += 'Fizz';
if (n % 5 === 0) result += 'Buzz';
if (!result.length) return n;
return result;
import xs from 'xstream';
import { run } from '@cycle/xstream-run';
import { makeDOMDriver, div, span } from '@cycle/dom';
// -- INTENT
// intent : domSource -> actions streams$
function intent(domSource) {
return {
@nickbalestra
nickbalestra / README.md
Last active November 6, 2016 12:42
A study plan to build applications with cycle

A study plan to build applications with cycle

What:

Cover all the major aspects in order to build apps with cycle.js: from drivers, to nested dialogues, from state management to testing.

Why:

I just started deep diving into cycle.js, therefore I'm primarly writing this for myself as part of my learning process. I am openly sharing my process to get feedback from the community as I'll probably get things wrong as I don't know any best practice yet(I kinda feel like cycling with side wheels on atm). I also hope this might serve others as well.

@nickbalestra
nickbalestra / Dialogue.js
Created November 4, 2016 15:31
MVI pattern using redux-like actions/reducer
import xs from 'xstream';
import {div, button} from '@cycle/dom'
function view(state$) {
const vtree$ = state$.map( state =>
div([
button('.increase', 'Moar'),
button('.decrease', 'Less'),
div(`Count: ${state.count}`)
])
@nickbalestra
nickbalestra / esnextbin.md
Created November 25, 2016 10:28
esnextbin sketch
@nickbalestra
nickbalestra / combineCycles.js
Last active December 18, 2016 00:12
A little utility to be used with redux-cycle-middleware or cycle.js in general
function combineCycles(...mains) {
return function(sources) {
const sinks = mains.map(main => main(sources))
const drivers = Object.keys(
sinks.reduce((drivers, sink) => Object.assign(drivers, sink), {})
)
const combinedSinks = drivers
.reduce((combinedSinks, driver) => {