How to use the @effectful/es-persist-serialization.managed function in @effectful/es-persist-serialization

To help you get started, we’ve selected a few @effectful/es-persist-serialization examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awto / effectfuljs / samples / persist-counters / storage.js View on Github external
export default async function* saveLocal(input) {
  if (!(await R.managed)) {
    yield* input;
    return;
  }
  try {
    const init = localStorage.getItem("counters");
    if (init) await load(JSON.parse(init));
  } catch (e) {}
  for await (const i of input) {
    yield i;
    if (i.type === "FLUSH") {
      const frame = await save();
      if (frame) localStorage.setItem("counters", JSON.stringify(frame));
      else yield i;
    }
  }
}
github awto / effectfuljs / samples / persist-boxes / state.js View on Github external
export async function* saveLocal(input) {
  if (!(await R.managed)) {
    yield* input;
    return;
  }
  try {
    const init = localStorage.getItem("boxes");
    if (init) {
      const state = R.read(JSON.parse(init));
      R.context().running = state.running;
      state.resume.resume();
      await R.abort;
    }
  } catch (e) {}
  for await (const i of addFlush(input)) {
    yield i;
    if (i.type === "DELETE" || i.type === "DONE") {
      let frame;
github awto / effectfuljs / samples / persist-counters / undoredo.js View on Github external
export default async function* undoRedoMain(input, dispatch) {
  yield* (await R.managed) ? main(input, dispatch) : input;
}