Skip to content

Instantly share code, notes, and snippets.

@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
(defn button [props _]
(om/component
(dom/button nil (:children props))))
(def render-out (om/render-to-object button {:children "text"}))
(is (= "text" (:children render-out))
@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 => {
@staltz
staltz / tiny-cycle-2.js
Created December 10, 2015 19:46
Tiny Cycle.js 2
function main() {
return {
DOM: Rx.Observable.timer(0, 1000)
.map(i => {
return {
tagName: 'h1',
children: [`Seconds elapsed ${i}`]
}
})
}
@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 / main.js
Created March 4, 2016 21:22
Cycle.js demo with MIDI and Web Audio
import {Observable, Disposable} from 'rx';
import {run} from '@cycle/core'
const jsondiffpatch = require('jsondiffpatch').create({
objectHash: function(obj) {
return obj.name;
}
});
function generateCurve(steps){
var curve = new Float32Array(steps)
@staltz
staltz / check-operators.js
Last active May 6, 2024 03:12
A node.js script to check how often are RxJS operators used
var operators = [
'\\.case',
'\\.create',
'\\.defer',
'\\.empty',
'\\.forkJoin',
'\\.from',
'\\.fromCallback',
'\\.fromEvent',
'\\.fromEventPattern',
@staltz
staltz / how.md
Last active May 6, 2024 03:12
How to debug Mocha tests written in Babel, running only in Node.js

Run this in one shell

./node_modules/.bin/mocha --debug-brk --compilers js:babel-register test/node

Then this in another shell

node-inspector

Then open the browser

@staltz
staltz / helper.js
Created June 6, 2016 10:56
How to use Stanga (https://github.com/milankinen/stanga) as a wrapper, not as a driver
// Generic helper function that takes a main() (the top-level component)
// and wraps it with Stanga logic
function wrapWithStanga(main, initialState) {
return function (sources) {
const modProxy$ = new Subject();
const modelSource = Model(initialState)(modProxy$);
sources.model = modelSource;
const sinks = main(sources);
sinks.model.subscribe(modProxy$);
@staltz
staltz / main.js
Created June 22, 2016 15:06
A-Frame + Cycle.js demo
import xs from 'xstream';
import Cycle from '@cycle/xstream-run';
import {h, makeDOMDriver} from '@cycle/dom';
require('aframe');
function main(sources) {
let vdom$ = xs.periodic(16).startWith(0).map(i =>
h('a-scene', [
h('a-sphere', {
attrs: {