Skip to content

Instantly share code, notes, and snippets.

View nickbalestra's full-sized avatar

Nick Balestra-Foster nickbalestra

View GitHub Profile
@nickbalestra
nickbalestra / streamFromStore.js
Last active December 19, 2016 22:45
Creates stream of states from a Redux store
import xs from 'xstream'
function streamFromStore(store) {
return xs.create(
{
start: function(listener){
this.unsubscribe = store.subscribe(() => listener.next(store.getState()))
},
stop: function(){
this.unsubscribe()
@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) => {
@nickbalestra
nickbalestra / esnextbin.md
Created November 25, 2016 10:28
esnextbin sketch
@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 / 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.

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 / 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;
function continentCounter (world, x, y) {
var board = world.slice();
if (board[x] === undefined || board[x][y] !== "land") {
return 0;
}
var count = 1;
board[x][y] = "counted";
@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] :