随笔分类 - Compose
摘要:function observe(obj) { for (const key in obj) { let internalValue = obj[key]; const funs = new Set() Object.defineProperty(obj, key, { configurable:
阅读全文
摘要:https://www.npmjs.com/package/ses Lockdown The lockdown() function also tames some objects including regular expressions, locale methods, and errors.
阅读全文
摘要:Concurrency + Channel (CSP): Concurrency is a way to run operation in isolated thread, a way to better utilize the CPU resources and handle multi simu
阅读全文
摘要:function getData(d) { setTimeout(() => { if (typeof d "number") { run.next(d/2) } else { run.next(d) } }, 500) } function* gen() { var x = 1 + (yield
阅读全文
摘要:Thunks Sync thunk: A blocker of code which has everything ready and can return the value directly. function add(x, y) { return x + y } const thunk = f
阅读全文
摘要:An example of callback implemnetation for handling async flow: function fakeAjax(url, cb) { var fake_responses = { file1: "The first text", file2: "Th
阅读全文
摘要:1. Basic version of signals We have a basic version of signal: const stack = [] export function createSignal(value) { const subscribers = new Set(); c
阅读全文
摘要:Implement two functions of Signals createSignal: return a tuple with read function and wrtie function createEffect: accept a function which will be ex
阅读全文
摘要:PubSub is one of the most foundational patterns for reactivity. Firing an event out with publish() allows anyone to listen to that event subscribe() a
阅读全文
摘要:Requirements: function strBuilder(str) { return strBuilder; // TODO } var hello = strBuilder("Hello, "); var kyle = hello("Kyle"); var susan = hello("
阅读全文
摘要:function f(...args) { return args; } function flip(fn) { return function flipped (arg1, arg2, ...args) { return fn(arg2, arg1, ...args) } } let z = fl
阅读全文
摘要:New broadcaster: compose: export let combine = (broadcaster1, broadcaster2) => listener => { let value1; let value2; let cancel1 = broadcaster1(value
阅读全文
摘要:To build out our word game, we will have to be able to share the word across a few places. This means we have to set up a broadcaster that will push t
阅读全文
[Javascript] Broadcaster + Operator + Listener pattern -- 25. Save Network Requests by Using a Cache
摘要:Caches exist to make things faster (at the expense of taking up more memory and possibly outdated results). Our live search is a great use case for im
阅读全文
摘要:In previous post, we check how to use ifElse to branch out the logic: https://www.cnblogs.com/Answer1215/p/14093562.html let inputToBooks = pipe( wait
阅读全文
摘要:So far, we've used filter to prevent values when a condition is met. Sometimes you want two different behaviors based on a condition which is where yo
阅读全文
摘要:export let mapError = transform => broadcaster => listener => { return broadcaster((value) => { if (value instanceof Error) { listener(transform(value
阅读全文
摘要:You often want to ignore values until the user performs a certain action. This lesson walks through setting up an allowWhen broadcaster that will only
阅读全文
摘要:To display a sequence of values in React, we can use our mapSequence operator, wrap it around a broadcaster, then pass that new broadcaster into our u
阅读全文
摘要:Instead of always combining useState and useEffect, when can create a utility useBroadcaster hook which allows us to pass in a broadcaster. export let
阅读全文