thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.41k stars 151 forks source link

[@thi.ng/rdom] `setScheduler` not behaving as expected #402

Closed maxsei closed 5 months ago

maxsei commented 1 year ago

It seems that setScheduler(new RAFScheduler()) does not behave properly because the number of job objects are out of sync with the DOM objects that are created (more DOM object are created that actually exists in the jobs stream). The only way I can have the list of jobs synced with the DOM is by using syncRAF.

import { defAtom, defCursor } from "@thi.ng/atom";
import * as rx from "@thi.ng/rstream";
import { $compile, $list, setScheduler, RAFScheduler } from "@thi.ng/rdom";

// setScheduler(new RAFScheduler());

const db = defAtom<State>({ jobs: [] });
const jobs = defCursor(db, ["jobs"]);
const jobsView = rx.syncRAF(rx.fromAtom(jobs))
const jobCreate = rx.stream<Job>();
jobCreate.subscribe({
  next: ({ start, end, ...rest }) => {
    jobs.swap((prev) => [
      ...prev,
      { ...rest, start: new Date(start), end: end && new Date(end) },
    ]);
  },
});

tx.run(
  tx.sideEffect((x) => jobCreate.next(x)),
  getJobs(), // not implemented here returns Job[]
);

const root = document.getElementById("root")
$compile($list(jobs, "div", {}, (x)=> `${x.start}`)).mount(root)
postspectacular commented 5 months ago

closing this since, schedulers have been removed with v1.0.0 (back in January 2024) - see commit message above for details...