Skip to content

Instantly share code, notes, and snippets.

View staltz's full-sized avatar

André Staltz staltz

View GitHub Profile
@staltz
staltz / app.js
Created June 28, 2015 11:55
Draft of Cycle.js HTTP Driver
const Cycle = require('@cycle/core');
const CycleWeb = require('@cycle/web');
const makeHTTPDriver = require('@cycle/http');
const h = CycleWeb.h;
function main(responses) {
const GITHUB_SEARCH_API = 'https://api.github.com/search/repositories?q=';
// This essentially models when search requests are supposed
// to happen
@staltz
staltz / .vimrc
Last active December 23, 2015 06:39
vim syntax highlighting for git-done TODO
" Append these to your .vimrc
syntax enable
au BufRead,BufNewFile *.todo setfiletype todo
au BufRead,BufNewFile TODO setfiletype todo
@staltz
staltz / first.js
Created December 10, 2015 19:59
Tiny Cycle.js 0
Rx.Observable.timer(0, 1000)
.map(i => `Seconds elapsed ${i}`)
.subscribe(text => {
const container = document.querySelector('#app');
container.textContent = text;
});
@staltz
staltz / tiny-cycle-1.js
Created December 10, 2015 18:53
Tiny Cycle.js 1
function main() {
return {
DOM: Rx.Observable.timer(0, 1000)
.map(i => `Seconds elapsed ${i}`)
};
}
const drivers = {
DOM: function DOMDriver(sink) {
sink.subscribe(text => {
h('div.container', [
h('label.nameLabel', 'Name:'),
h('input.myinput', {attributes: {type: 'text'}}),
h('hr'),
h('h1.greeting', `Hello ${name}`)
])
// or
div('.container', [
@staltz
staltz / dom$.js
Last active August 29, 2015 14:22 — forked from anonymous/dom$.js
import Cycle from 'cyclejs';
const { h, Rx } = Cycle;
// all html/svg element names <<
var elements = [
'a',
'abbr',
'address',
'area',
@staltz
staltz / gist:78140b885f366886d9b5
Last active August 29, 2015 14:19
Terse Cycle.js

Terse Cycle.js

Take Cycle's primal example, on the README:

import Cycle from 'cyclejs';
let {Rx, h} = Cycle;

let name$ = Cycle.createStream(function model(changeName$) {
@staltz
staltz / about-mercury.md
Last active August 29, 2015 14:14
El Mercurio

Rough sketch of how is the flow of data in Mercury.

                           │
  Event channels  <───────────── dom-delegator (events)
       │                   │           ^
       V  (imperative)                 │
  View state               │          DOM
@staltz
staltz / gist:2f0704b1ecadc42fb0ab
Last active August 29, 2015 14:13
Cycle components decouple abstraction from implementation

Cycle custom elements decouple the component's abstraction from its implementation.

When you use a React component like

<div>
  <NewHotness />
</div>

You are pulling in that specific NewHotness component. You actually had to explicity import the NewHotness component before using it.

@staltz
staltz / delayUntil.xtend
Created September 24, 2014 17:10
.delayUntil() for RxJava
/**
* Delays all items from the source Observable up until when the other Observable
* emits its first item. After the other Observable emitted its first item,
* the source items are not delayed.
*
* source: ---s-s---s----------s---s----s---s---s--|>
* other: ------------o------o-------o------o-----|>
* result: ------------sss-----s---s----s---s---s--|>
*
* @param first