npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kefir-extra

v0.5.3

Published

A collection of combinators and helpers for the Kefir library

Downloads

6

Readme

Kefir Extra

Build Status

A collection of combinators and helpers for the Kefir library.

import * as K from 'kefir-extra'

const bus = K.createPropertyBus('INITIAL')
const combined = K.combinePropertyObject({
  a: bus.property,
  b: K.constant(true),
})

combined.log()
// {a: 'INITIAL', b: true}

bus.set('OTHER')
// {a: 'OTHER', b: true}

API

The kefir-extra module exports all functions from the kefir package at version v3.6.1 plus the following.

import * as K from 'kefir-extra'

createStreamBus() | createPropertyBus() | combinePropertyObject() | eventSum() | onValue() | getValue() | getRef() | promiseProperty() | sampleFrom()

import * as KM from 'kefir-extra/mock'

createProperty() | createStream()

K.createStreamBus()

Create a bus that allows you to emit values on a stream.

const bus = K.createStreamBus()
bus.stream.log()
bus.emit('VALUE')
// <value> 'VALUE'
bus.end()
// <end>

The returned bus object has the following properties

  • stream: Stream<T>
  • emit(T): void
  • end(): void

K.createPropertyBus(initial)

Create a bus that allows you to set the current value of a property.

const bus = K.createPropertyBus('INITIAL')
bus.property.log()
// <value:current> 'INITIAL'
bus.set('VALUE')
// <value> 'VALUE'
bus.end()
// <end>

The returned bus object has the following properties

  • property: Stream<T>
  • set(T): void
  • end(): void

K.combinePropertyObject(props)

Combines an object with properties as values into a property whose current value is an object combining the current values.

const combined = K.combinePropertyObject({
  a: K.constant('A'),
  b: K.constant('B'),
})
combined.log()
// <value:current> {a: 'A', b: 'B'}

Note that this function asserts that all values in the argument are properties.

K.eventSum(events)

Since v0.5.2

Merges events by wrapping values in a {type, value} pair.

const sum = K.eventSum({
  a: K.sequentially(7, ['a1', 'a2'])
  b: K.sequentially(10, ['b1'])
})
sum.log()
//  7ms { type: 'a', value: 'a1' }
// 10ms { type: 'b', value: 'b2' }
// 14ms { type: 'a', value: 'a2' }

K.onValue(obs, handler)

Add a handler to be called when the observable emits a value.

Returns a function that unsubcribes the handler.

const off = K.onValue(obs, function (val) {
  console.log(val)
})
// Prints values
off()

While the handler is subscribed we throw all errors on the stream.

K.getValue(property)

Since v0.5.1

Gets the current value of a property and throws an error if the property does not have a value.

const p = K.constant('A')
K.getValue(p) // => 'A'

Calling this function might have side-effects since we subscribe to the property and then immediately unsubscribe again.

WARNING: Use this sparsely. Using this leads to un-idomatic code.

K.getRef(property)

Since v0.5.3

Returns a reference object to the current value of the property.

const ref = K.getRef(prop)
ref.value // => current value
ref.dispose() // => unsubcribes once and for all

The function subscribes to the property immediately and sets the value property of the reference object.

The reference object also has a dispose() function that unsubscribes from the property. In addition it cleans up the reference deleting both the value and dispose properties.

K.promiseProperty(promise)

Since v0.5.1

Turns a promise into a property that holds a promise state object.

The promise state object has a state property that is either 'pending', 'resolved', or 'rejected'. If the state is “resolved” then the object has a value property holding the resolved value. If the state is “rejected” the object has an error property.

K.promiseProperty(promise)
.onValue((state) => {
  if (state.state === 'pending') {
    console.log('pending')
  } else if (state.state === 'resolved') {
    console.log('resolved', state.value)
  } else if (state.state === 'rejected') {
    console.log('rejected', state.error)
  }
})

K.sampleFrom(obs, sampler)

Since v0.5.3

Create a property that is updated whenever the observable emits a new event. The sampler function is used to obtain the value.

const prop = K.sampleFrom(obs, () => {
  // called on initial subscription and whenever obs emits a new event

  // Return the current property value
  return value
})

KM.createProperty(initial)

Returns an object that has the same interface as a Kefir property and the additional set(value) and end() methods. These methods can be used to control the state of the property.

You should only use this for testing purposes.

KM.createStream()

Returns an object that has the same interface as a Kefir stream and the additional emit(value) and end() methods. These methods can be used to control the state of the stream.

You should only use this for testing purposes.