Skip to content

Instantly share code, notes, and snippets.

View staltz's full-sized avatar

André Staltz staltz

View GitHub Profile
@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 / migration-guide.md
Last active December 19, 2023 22:14
How to show migration guides in GitHub Markdown

How to show migration guides in GitHub Markdown

Use the diff code highlighting tag.

  ```diff
  - foo
  + bar

Example:

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 / slim-cycle-core.js
Created September 22, 2015 12:35
Cycle.js without sanity checks and comments in a single file. Don't use this, use normal Cycle.js. :-)
let Rx = require(`rx`)
function makeRequestProxies(drivers) {
let requestProxies = {}
for (let name in drivers) {
if (drivers.hasOwnProperty(name)) {
requestProxies[name] = new Rx.ReplaySubject(1)
}
}
return requestProxies
@staltz
staltz / scope.js
Last active November 20, 2023 23:24 — 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.
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');
}
@staltz
staltz / jsx-quasi.js
Last active May 6, 2022 17:02 — forked from lygaret/index.js
ES6 Quasi-Literal for JSX
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 / router.js
Last active August 5, 2019 08:42 — forked from axefrog/router.js
Simple router driver for Cycle.js utilising Router5 for routing functionality and adapting some of the code from VisionMedia's Page.js for automatic link click intercepting
'use strict';
import {Router5, RouteNode} from 'router5';
import logger from '../logger';
// The set of valid sink functions includes synchronous state-affecting router functions that do not require a callback
// and which do not have a significant return value other than the router object itself.
const validSinkFuncs = ['add','addNode','canActivate','deregisterComponent','navigate','registerComponent','setOption','start','stop'];
function validateAndRemapSinkArgument(arg) {
@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 / app.kt
Last active January 26, 2018 01:20
Cycle giving baby steps into Kotlin
import kotlin.browser.document
import kotlin.browser.window
// Type definitions
native("Cycle")
val Cycle : dynamic = noImpl
native("Cycle.h")
fun h(tagName: String) : VTree = noImpl
@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',