Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Frank Lemanschik
@frank-dspeed
that exists already
if you merge 2 streams you get a serial stream
if you zip them you get always 2 pairs
the result of merge should be equal isn't it
i don't even understand your spec result :)
Jack Jennings
@jackjennings
The spec function takes a JS object where the values are streams, and emits objects in the same structure but with the last stream value in each key/value pair.
If this exists in core I would be happy to see how
Jack Jennings
@jackjennings
Juha Paananen
@raimohanska
This look almost exactly like Bacon.combineTemplate
There seems to be a Kefir version too: https://github.com/ahomu/kefir.combinetemplate
Jack Jennings
@jackjennings
✌️
Frank Lemanschik
@frank-dspeed
it looks a bit like what we do with canjs
and our can-computes and can-stream-kefir
if your searching for a dom diffing framework
that suports kefir streams to update values realtime
we have nice realtime template bindings for streams :D
Ahmed Fasih
@fasiha
Is there a way to reduce or fold a Kefir stream into a scalar value? I’m looking for max specifically.
Ahmed Fasih
@fasiha
Ah, I can scan and last :)
Inkata
@Inkata
Is this the right place to ask kefirjs questions?
Juha Paananen
@raimohanska
Damn right!
Bruno Pinto
@bpinto

Hi there, I've started using kefir recently in conjunction with karet (react) and there is one thing I'm trying to achieve but I'm not sure if I'm on the right track.

In order to mitigate potential untracked subscriptions, I would like to count the number of active observables after a test expect(countOfActiveObservables).toEqual(0). I have looked at the codebase and this doesn't exist so I'm trying to create this via a Proxy but I'm not sure if the approach I'm working on is a good one.

I've noticed that there is a _setActive method on K.Observable that maye be what I'm looking for, and I used the following code to track number of active subscriptions:

function proxy(f) {
  return new Proxy(f, {
    apply(target, thisArg, args) {
      if (thisArg._active && !args[0]) { count -= 1 }
      if (!thisArg._active && args[0]) { count += 1 }
      target.apply(thisArg, args)
    }
  });
}

K.Observable.prototype._setActive = proxy(K.Observable.prototype._setActive)

Would this count subscriptions correctly? Should I be looking at another function? Thanks for any advice

Bruno Pinto
@bpinto
I've came up with another idea, a test where I had forgotten to unsubscribe failed with this code but not sure if it wouldn't break objects that define _onActivation:
'use strict'

const Kefir = require('kefir')

// from kefir/utils/objects/extend
function extend (target /*, mixin1, mixin2... */) {
  for (let i = 1; i < arguments.length; i++) {
    for (const prop in arguments[i]) {
      target[prop] = arguments[i][prop]
    }
  }

  return target
}

extend(Kefir.Observable.prototype, {
  _onActivation () {
    Kefir.activeObservables.push(this)
  },
  _onDeactivation () {
    Kefir.activeObservables.splice(Kefir.activeObservables.indexOf(this), 1)
  },
  initActiveObservables () {
    Kefir.activeObservables = []
  }
})

module.exports = Kefir
Bruno Pinto
@bpinto

I solved the above problem of redefining _onActivation and onDeactivation by doing this:

const originalOnActivation = Kefir.Observable.prototype._onActivation
const originalOnDeactivation = Kefir.Observable.prototype._onDeactivation

extend(Kefir.Observable.prototype, {
  _onActivation () {
    Kefir.activeObservables.push(this)
    originalOnActivation()
  },
  _onDeactivation () {
    Kefir.activeObservables.splice(Kefir.activeObservables.indexOf(this), 1)
    originalOnDeactivation()
...

and now it calls both functions. I didn't need to use Proxy.