Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.withLatestFrom(later(1, "foo"), …) depends on JS runtime #803

Open
semmel opened this issue Oct 17, 2022 · 1 comment
Open

.withLatestFrom(later(1, "foo"), …) depends on JS runtime #803

semmel opened this issue Oct 17, 2022 · 1 comment

Comments

@semmel
Copy link
Member

semmel commented Oct 17, 2022

B.later(1, "foo") is like B.later(0, "foo") but only when running in Node – as different from when running in browsers.

demo code:

const B = require('baconjs'),
   concat = (a, b) => a + b, 
   s = B.once('foo').withLatestFrom(B.later(1, 'bar'), concat);
// let it run
s.onValue(console.log)

For a nice surprise execute that in Node, e.g. from a project shell where baconjs is installed:

node -e "const B = require('baconjs'), concat = (a, b) => a + b, unsub = B.once('foo').withLatestFrom(B.later(1, 'bar'), concat).onValue(console.log)"
# -> foobar

whereas in browser dev tools there is no event output :

import('./node_modules/baconjs/dist/Bacon.mjs').then(m => { globalThis.B = m; });
var concat = (a, b) => a + b;
var unsub = B.once("foo")
.withLatestFrom(B.later(1, "bar"), concat)
.onValue(s => { console.log(`sampled: "${s}"`); })

I guess I have to treat synchronicity or atomic updates with a grain of salt. 🤔

@kryptt
Copy link

kryptt commented Apr 5, 2023

I'm bit by this as well withLatestFrom seems to be swallowing events around a potential "circular" dependency:

  const qUnavailable = Bacon.constant(true).flatMap(() =>
    qProp.map(query => query.attr === undefined)
  );

  const eventsSub = events
    .log("searchEvent")
    .holdWhen(qUnavailable)
    .log("searchQueryReady")
    .withLatestFrom(
      qProp.log("query"),
      (event, query) => ({
        event: event,
        query: query,
      })
    ).onValue();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants