Skip to content

Instantly share code, notes, and snippets.

Avatar
🐦
tsers

Matti Lankinen milankinen

🐦
tsers
  • Finland
View GitHub Profile
@milankinen
milankinen / useSubscription.diff
Created Aug 14, 2019
Modified useSubscription
View useSubscription.diff
@@ -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;
View example.ts
import * as L from "partial.lenses";
interface State {
foo: {
lol: number;
bal: string;
};
items: Item[];
}
@milankinen
milankinen / index.js
Last active Nov 13, 2018
Sync promise resolution with fibers (tested with Node v11.1.0)
View index.js
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 Feb 8, 2017
CULLI state (de)composition
View index.js
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 Oct 28, 2016
Redux devtools integration with @culli/store
View devtools.js
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 Oct 24, 2016
CULLI teaser
View main.js
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 Sep 22, 2016
Reduxish Stanga
View main.js
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
}
View monkey.js
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 Mar 22, 2016
Cycle "advanced" counter with parent state sharing
View main.js
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 Mar 22, 2016
"Advanced" Cycle.js list example
View app.js
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$) {
You can’t perform that action at this time.