Skip to content

Instantly share code, notes, and snippets.

View milankinen's full-sized avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
View GitHub Profile
@milankinen
milankinen / useSubscription.diff
Created August 14, 2019 10:15
Modified useSubscription
@@ -23,8 +23,8 @@ export function useSubscription({ getCurrentValue, subscribe }) {
useEffect(() => {
let didUnsubscribe = false;
-
- const checkForUpdates = () => {
+ // NOTICE: value coming from subscription not from getCurrentValue !!!
+ const onValue = value => {
if (didUnsubscribe) {
return;
@milankinen
milankinen / example.ts
Last active March 29, 2019 15:46
Lissityyppei
import * as L from "partial.lenses";
interface State {
foo: {
lol: number;
bal: string;
};
items: Item[];
}
@milankinen
milankinen / index.js
Last active November 13, 2018 23:29
Sync promise resolution with fibers (tested with Node v11.1.0)
const vm = require("vm");
const { resolve, run } = require("./sync");
// in "master"
const calls = [];
const log = console.log.bind(console);
const random = Math.random;
// in "worker"
@milankinen
milankinen / index.js
Created February 8, 2017 18:41
CULLI state (de)composition
import * as O from "most"
import * as L from "partial.lenses"
import DOM from "@culli/dom"
import Store, {Memory, byType} from "@culli/store"
import {run} from "@cycle/most-run"
// partial.lenses lens => culli lens
const P = (pl) => ({
get: L.get(pl),
set: L.set(pl)
@milankinen
milankinen / devtools.js
Last active October 28, 2016 21:07
Redux devtools integration with @culli/store
import {O, extend} from "@culli/base" // you can replace this with your own streaming library if you want
import Memory from "./memory"
function ReduxDevtools(initial) {
const devtools = window.__REDUX_DEVTOOLS_EXTENSION__
if (!devtools) {
return Memory(initial)
}
@milankinen
milankinen / main.js
Last active October 24, 2016 20:42
CULLI teaser
import * as O from "most"
import {run} from "@cycle/most-run"
import DOM from "@culli/dom"
import Store, {Memory} from "@culli/store"
import HTTP from "@culli/http"
run(GithubSearch, {
DOM: DOM("#app"),
// create store using in-memory persintence
@milankinen
milankinen / main.js
Last active September 22, 2016 21:03
Reduxish Stanga
import {Observable as O} from "rx"
const store = reducer => R.lens(R.identity, reducer)
const myStore = store((action, state) => {
switch (action.type) {
case "INC": return state + 1
case "DEC": return state - 1
default: return state
}
@milankinen
milankinen / monkey.js
Created April 8, 2016 07:27
Rx .log monkey
Rx.Observable.prototype.log = function(prefix) {
return process.env.NODE_ENV !== "development" ? this : this
.doOnCompleted(() => console.log(prefix, "<completed>")) // eslint-disable-line
.do(x => console.log(prefix, x)) // eslint-disable-line
}
// const obs = Rx.Observable.fromEvent(text, "input")
// .log("InputEvent:")
// .map(e => e.target.value)
// .filter(t => !!t)
@milankinen
milankinen / main.js
Created March 22, 2016 22:49
Cycle "advanced" counter with parent state sharing
import Rx, {Observable as O} from "rx"
import Cycle from "@cycle/core"
import {h, makeDOMDriver} from "@cycle/dom"
import isolate from "@cycle/isolate"
function Counter({DOM, initial$}) {
const mod$ = O.merge(
DOM.select(".dec").events("click").map(ev => state => state - 1),
DOM.select(".inc").events("click").map(ev => state => state + 1)
)
@milankinen
milankinen / app.js
Created March 22, 2016 20:58
"Advanced" Cycle.js list example
import {Observable as O} from 'rx'
import L from "partial.lenses"
import R from "ramda"
import {h3, div} from '@cycle/dom'
import isolate from '@cycle/isolate'
import Ticker from './ticker'
import {liftListById, flatCombine, flatMerge} from "stanga"
function intent(tickers$) {