Skip to content

Late-subscribing only works if early subscribing occurred #7

@bjnsn

Description

@bjnsn

When a remembered source receives a value, that value is not emitted to late subscribers unless that source has already been subscribed to.

Perhaps this is the intended behavior, but to me this was unexpected. See: https://stackblitz.com/edit/js-t8rvxy?file=index.js

import remember from "callbag-remember";
import { pipe, forEach } from "callbag-basics";
import fromFunction from "callbag-from-function";

const { source, emitter } = fromFunction();

const rem$ = remember(source);

// Late subscription does not receive the value unless early subscription enabled
/*
pipe(
  rem$,
  forEach(value => {
    console.log("early-subscribe", value);
  })
);
*/

emitter(111);

setTimeout(() => {
  pipe(
    rem$,
    forEach(value => {
      console.log("late-subscribe", value);
    })
  );
}, 1000);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions