Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Eugene Shulga
    @ujeenator

    I was a little surprised that the throttle function works with a delay, even for the very first event

    I searching something like on picture

    I have found very old thread, where was mentioned limitThroughput(х) function, but look like since then it was not merged in master branch:
    baconjs/bacon.js#82
    Eugene Shulga
    @ujeenator
    Screen Shot 2018-06-23 at 11.37.46 PM.png
    BasH
    @bas080
    How would I go about using bacon with node's streams?
    Juha Paananen
    @raimohanska
    You should of course consider whether you need Bacon when working with Node streams first. If you want to use it, you can of couse, by building a simple adapter. Here's something I wrote years ago: https://gist.github.com/raimohanska/6202053
    @bas080 ^
    Matthew Hayden
    @mrehayden1
    Has anyone successfully shimmed Bacon, espciallybacon.model and bacon.jquery with webpack? The scripts-loader results in some odd behaviour, .ajax() not being defined on some streams made with bacon.jquery <event>E streams, and imports-loader results in errors at compile time.
    Galileo Sanchez
    @galileopy
    hello
    stream.subscribe(event => event.isError()) is throwing an exception, apparently event is not an event but the actual value on the stream, this is with bacon 2.0.9
    Matthew Hayden
    @mrehayden1
    @galileopy use .onError I think it is to get the errors
    Galileo Sanchez
    @galileopy
    this is my complete function
      const cancel = data.subscribe((event) => {
        console.log(event)
        if (event.isError()){
          cancel()
          next(event.error)
          return
        }
        if (event.isEnd()) return res.json({ success: true })
      })
    Matthew Hayden
    @mrehayden1
    if you want errors in the stream use .mapError
    Galileo Sanchez
    @galileopy
    I'm trying to avoid having onError(), onEnd() this goes in an express middleware, and I'm trying to avoid the can't set headers after they're sent error on express
    Matthew Hayden
    @mrehayden1
    you don't get access to the Nexts in .subscribe as far as I recall
    Galileo Sanchez
    @galileopy
    that next is from an express middleware
    I should be able to call just one of res.json({ success: true }), or next(error)
    I made sure the stream emits just one value before ending
    Matthew Hayden
    @mrehayden1
    event is a value, Next is also the name of the contructor in Bacon for a normal value
    sorry, i thought that's what you were talking about
    Galileo Sanchez
    @galileopy

    my old code was like this

    data.onEnd(finishRequest)
    data.onError(dispatchError)

    but when an error occurs both functions are called. I need to call just one of them. one on error, and one on success, but never both.

    looks easy, I didn't expect it to call both onEnd, and onError, when there was an error
    also
    const data = getData()//returns stream
    .endOnError()
    .fold([], concat)
    that's basically what data looks like
    Matthew Hayden
    @mrehayden1
    if you're using .endOnError then your .onEnd handler will be called on an error
    Galileo Sanchez
    @galileopy
    I also need to make sure that I react only to the first error
    Matthew Hayden
    @mrehayden1
    @galileopy you should be able to unsubscribe
    Galileo Sanchez
    @galileopy
    I'll try that
    Matthew Hayden
    @mrehayden1
    or use a variable in the outer scope
    Galileo Sanchez
    @galileopy
    thanks
    I'll try this.
      const data = getData()//returns stream, took away endOnError()
      .fold([], concat)
      const unsubscribe = dato$.onValue(() => {
        unsubscribe()
        res.json({ success: true })
      })
      const cancel = dato$.onError((err) => {
        unsubscribe()
        cancel()
        next(err)
    Juha Paananen
    @raimohanska
    Commenting on the original post by @galileopy : Yes you can check for isError in the callback in subscribe. The error in your example is that you're treating isError as a function while, in 2.0, it's simply a boolean field.
    So, you're original version should work if you replace isError() and isEnd() by isError and isEnd.
    Is there some outdated documentation out there that we should update?
    Matthew Hayden
    @mrehayden1
    @raimohanska no, I was just confusing .subscribe and .onValue
    Juha Paananen
    @raimohanska
    If you want a more convenient way to stop listening to events, you can always return Bacon.noMore from your callback. Then you don't need to call unsubscribe(). See https://github.com/baconjs/bacon.js/#cleaning-up
    Galileo Sanchez
    @galileopy
    I see, @raimohanska, the documentation seems to be alright, I started reading the API v1, docs, and when reading API v2 I didn't realize that isError, and isEnd were listed as properties of the event object.
    Juha Paananen
    @raimohanska

    Oh btw, if someone's interested in helping me in converting Bacon to Typescript, please ping me!

    There's branch and a pull-request here baconjs/bacon.js#717

    Currently I'd appreaciate help with getting to the point where I can set "noImplicitAny": true in tsconfig :)

    Juha Paananen
    @raimohanska
    Oops, got to that point already.
    Matthias Seemann
    @semmel
    I've got trouble putting Bacon.once().holdWhen(v) inside a .flatMapConcat. .holdWhen seems to let all events through regardless of the "real" value of the property v.
    It's so strange that I put a demo on repl.it
    Matthias Seemann
    @semmel
    In a nutshell: Once v becomes falsy it is never updated in this expression: source.flatMapConcat(x => Bacon.once(x).holdWhen(v)). Thus the inner holdWhen lets all of source pass indefinitely.
    Matthias Seemann
    @semmel
    Mmmh. The problem is that v is lazy w.r.t. the rest of the program.
    Is it that Bacon.once(x).holdWhen(v) subscribes to v only if v is truthy. When v becomes falsy the subscription is dropped and updates to v go into the nirvana?
    Matthias Seemann
    @semmel
    Okay my mistake, I know the FAQ Why isn't my Property updated?, but this was very hard for me to spot.
    So when I summarise for myself: The "current" value of a property is the value of the latest event in the stream at the last time the property had any subscribers.
    IMO this makes the behaviour of properties so mutable and thus hard to reason about.
    On the other hand I see justified reason for the cancellation of asynchronous tasks (e.g. AJAX fetch). Maybe one could do it the other way round: "Cancellability (Lazyness) is an opt-in and Eagernaess is the default"?
    Galileo Sanchez
    @galileopy
    hi, there use to be a nice tutorial on eventstreams on the bacon page, one that had a very nice event diagram with clear symbols for properties, user actions, and event streams.
    what happened to it?
    It was an example of a login page
    I'd like to see that diagram to get an idea on how to document some of my streams, but I can't find it.
    My bad, it is under Tutorials
    Galileo Sanchez
    @galileopy
    Hi, can I PR to fix the documentation in API v2, so that the example under slidingWindow conforms to the same style used in other examples?

    Instead of

    For example, if you have a stream s with value a sequence 1 - 2 - 3 - 4 - 5, the respective values in s.slidingWindow(2) would be [] - [1] - [1,2] - [2,3] - [3,4] - [4,5]. The values of s.slidingWindow(2,2)would be [1,2] - [2,3] - [3,4] - [4,5].

    source:                       1 2 3 4 5
    sourrce.slidingWindow(2):     [ ]   [1]   [1,2] [2,3] [3,4] [4,5] [5]
    sourrce.slidingWindow(2, 1):  [1]   [1,2] [2,3] [3,4] [4,5] [5]
    sourrce.slidingWindow(2, 2):  [1,2] [2,3] [3,4] [4,5]