Skip to content

Instantly share code, notes, and snippets.

@pfgray
Created December 23, 2020 17:42
Show Gist options
  • Save pfgray/190abc22de2cee36d528660d82cd9f32 to your computer and use it in GitHub Desktop.
Save pfgray/190abc22de2cee36d528660d82cd9f32 to your computer and use it in GitHub Desktop.
most thing
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