View index.js
const flatMapLatest = (fn, stream) =>
stream.publish(s => s.flatMap(v => fn(v).takeUntil(s)));
const flatMapLatest = (fn, stream, resultSelector) => stream.publish(s => {
return s.flatMap(v => fn(v).map(v2 => resultSelector(v, v2)).takeUntil(s));
});
const delay = (source, delay) => source.flatMap(e => Rx.Observable.timer(delay).mapTo(e))
const debounceTime = (time, stream) => flatMapLatest(v => of(v).delay(time), stream);
View patch.js
const typeOf = ob => ob.toString()
const forEach = (fn, l) => typeOf(l) === '[object Object]'
? forEach(k => fn(l[k], k), Object.keys(l))
: Array.from(l).forEach(fn)
const patch = (elm, node) => {
if(elm === node) return elm
if(typeOf(elm) === '[object Text]') {
elm.textContent = node.textContent
View ActionLogger.ts
export function logger (action: any, state0: any, state1: any, effect: any) {
if (!getGlobalConfig().dispatcherLogs) return
let actionName: string[] = []
while (action instanceof Action) {
actionName.push(action.type)
action = action.value
}
console.groupCollapsed(actionName.join('/'))
console.log('ACTION', action)
View cache-morphism.js
function test () {
const cache = {}
function create (type) {return {type: type, value: new Date() }}
return function (type) {
if (cache[type]) return cache[type]
const c = create(type)
cache[type] = c
return c
}
}
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>call vs apply #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
View sidenav-benchmarker.js
(function (ctx) {
'use strict'
ctx.TouchBM = function (selector, {min = 0, max = 300} = {min: 0, max: 300}) {
const nav = document.querySelector(selector)
class TouchEventCustom extends TouchEvent {
constructor(type, changedTouches) {
super(type)
this.__changedTouches = changedTouches
}
get changedTouches() { return this.__changedTouches }