Skip to content

Instantly share code, notes, and snippets.

💔
GitHub was acquired

André Staltz staltz

💔
GitHub was acquired
Block or report user

Report or block staltz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@staltz
staltz / single-err-catcher.js
Created May 3, 2014
Q promises single error catcher
View single-err-catcher.js
var Q = require('q');
function delaydo(x) {
var deferred = Q.defer();
setTimeout(function() {
if (x === 2) {
console.log("reject: "+x);
deferred.reject(x);
}
else {
@staltz
staltz / promises-pyramid.js
Created May 3, 2014
Q promises pyramid of doom
View promises-pyramid.js
var Q = require('q');
function delaydo(x) {
var deferred = Q.defer();
setTimeout(function() {
if (x === 2) {
console.log("reject: "+x);
deferred.reject(x);
}
else {
@staltz
staltz / point-wise-err-handlers.js
Last active Aug 29, 2015
Q promises point-wise error handling
View point-wise-err-handlers.js
var Q = require('q');
function delaydo(x) {
var deferred = Q.defer();
setTimeout(function() {
if (x === 2) {
console.log("reject: "+x);
deferred.reject(x);
}
else {
@staltz
staltz / delayUntil.xtend
Created Sep 24, 2014
.delayUntil() for RxJava
View delayUntil.xtend
/**
* 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
@staltz
staltz / gist:2f0704b1ecadc42fb0ab
Last active Aug 29, 2015
Cycle components decouple abstraction from implementation
View gist:2f0704b1ecadc42fb0ab

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.

View about-mercury.md

https://github.com/Raynos/mercury

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

                           │
  Event channels  <───────────── dom-delegator (events)
       │                   │           ^
       V  (imperative)                 │
  View state               │          DOM
View gist:78140b885f366886d9b5

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$) {
View dom$.js
import Cycle from 'cyclejs';
const { h, Rx } = Cycle;
// all html/svg element names <<
var elements = [
'a',
'abbr',
'address',
'area',
@staltz
staltz / jsx-quasi.js
Last active Aug 29, 2015 — forked from lygaret/index.js
ES6 Quasi-Literal for JSX
View jsx-quasi.js
define(function(require) {
var React = require('react');
var paramRegex = /__(\d)+/;
var parser = new DOMParser();
var errorDoc = parser.parseFromString('INVALID', 'text/xml');
var errorNs = errorDoc.getElementsByTagName("parsererror")[0].namespaceURI;
// turns the array of string parts into a DOM
// throws if the result is an invalid XML document.
@staltz
staltz / scope.js
Last active Aug 31, 2015 — forked from axefrog/scope.js
An idea for scoping Cycle.js child components/dialogues in the context of their parent. Any driver can optionally supply a scope() function, which returns a scoped instance of itself. A driver can also supply an unscope() function which returns a transformed instance of its associated sink. Anything that is scope-unaware is preserved.
View scope.js
function runInScope(main, sources, context, ...args) {
if(!main) {
throw new Error('A "main" function must be supplied, which will be called in scope and from which a (sinks) object will be returned');
}
if(!sources) {
throw new Error('A source drivers object must be supplied, to which scoping can be applied');
}
if(!context) {
throw new Error('A scope context object must be supplied, either as a string, or as an object of key/value pairs');
}
You can’t perform that action at this time.