Created
December 23, 2020 17:42
-
-
Save pfgray/190abc22de2cee36d528660d82cd9f32 to your computer and use it in GitHub Desktop.
most thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as most from "most"; | |
import { event } from "most-subject"; | |
import { newDefaultScheduler, currentTime } from "@most/scheduler"; | |
import { runEffects, propagateEventTask, tap } from "@most/core"; | |
import { createAdapter } from "@most/adapter"; | |
import { create } from "@most/create"; | |
const scheduler = newDefaultScheduler(); | |
const [induce, events] = createAdapter<number>(); | |
type UseState<A> = [A, (a: A) => void]; | |
export const uzeState = <A>(initial: A) => | |
create<UseState<A>>((add) => { | |
const addOne = (a: A) => { | |
add([a, addOne]); | |
}; | |
add([initial, addOne]); | |
}); | |
let strTurn = true; | |
const countStream = uzeState(0).tap((n) => { | |
console.log(`n changed! ${n[0]}`); | |
}); | |
const strStream = uzeState("y"); | |
const myAppState = strStream.combine( | |
(str, count) => ({ | |
count, | |
str, | |
}), | |
countStream | |
); | |
// .observe(({ str: [str, setStr], count: [n, setN] }) => { | |
// console.log("******"); | |
// console.log(str); | |
// console.log(n); | |
// setTimeout(() => { | |
// strTurn ? setStr(str + "o") : setN(n + 1); | |
// strTurn = !strTurn; | |
// }, 2000); | |
// }); | |
const App = () => { | |
// const [n, setN] = useState(countStream) | |
// const [str, setStr] = useState("y") | |
// const [n, setN] = useEffect(() => {setN}, [n]) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment