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 🙏

© 2026 – Pkg Stats / Ryan Hefner

xaret

v1.0.5

Published

Helpers to embed Rx Observables in React VDOM following the Calmm architecture

Readme

[ | Contrived Example | Reference ]

Xaret

Xaret is a library that allows you to embed RxJS observables into React Virtual DOM. Embedding observables into VDOM has the following benefits:

  • It allows you to use only functional components, because you can then use observables for managing state and ref for component lifetime, leading to more concise code.
  • It helps you to use React in an algorithmically efficient way:
    • The body of a functional component is evaluated only once each time the component is mounted.
    • Only elements that contain embedded observables are rerendered when changes are pushed through observables. An update to a deeply nested VDOM element can be an O(1) operation.

Using Xaret couldn't be simpler. You just import * as React from "xaret" and you are good to go.

npm version

Contents

Contrived Example

To use Xaret, you simply import it as React:

import * as React from "xaret"

and you can then write React components:

const oncePerSecond$ = Rx.Observable.interval(1000)

const Clock = () =>
  <div>
    The time is {oncePerSecond$.map(() => new Date().toString())}.
  </div>

Edit nwmo5r1lj

with VDOM that can have embedded Rx.Observable observables. This works because Xaret exports an enhanced version of createElement.

NOTE: Xaret does not pass through other named React exports. Only createElement is exported, which is all that is needed for basic use of VDOM or the Babel JSX transform.

NOTE: The result, like the Clock above, is just a React component. If you export it, you can use it just like any other React component and even in modules that do not import xaret.

Reference

xaret-lift attribute

Xaret only lifts built-in HTML elements implicitly. The xaret-lift attribute on a non-primitive element instructs Xaret to lift the element.

For example, you could write:

import * as RR    from "react-router"
import * as React from "xaret"

const Link1 = ({...props}) => <RR.Link xaret-lift {...props}/>

to be able to use Link1 with embedded Rx.Observable observables:

<Link1 href="https://www.youtube.com/watch?v=Rbm6GXllBiw"
       ref={elem => elem && elem.focus()}>
  {Rx.Observable.from([3, 2, 1, "Boom!"], Rx.Observable.interval(1000))}
</Link1>

Note that the ref attribute is only there as an example to contrast with $$ref.

fromObservable(observableVDOM)

fromObservable allows one to convert a Kefir observable of React elements into a React element. It is useful in case the top-most element of a component depends on a Kefir observable.

For example:

import {fromObservable} from "xaret"

const Chosen = ({choice}) =>
  fromObservable(Rx.Observable.fromPromise(fetch('//api/json')).map(result => <div>{result}</div>))

Note that the point of using fromObservable in the above example is that we don't want to wrap the Rx.Observable.fromPromise(...) inside an additional element like this:

const Chosen = ({choice}) =>
  <div>
    {Rx.Observable.fromPromise(fetch('//api/json')).map(result => <div>{result}</div>)}
  </div>

fromClass(Component)

fromClass allows one to lift a React component.

For example:

import * as RR from "react-router"
import {fromClass} from "xaret"

const Link2 = fromClass(RR.Link)

WARNING: A difficulty with lifting components is that you will then need to use the $$ref attribute, which is not necessary when using xaret-lift to lift an element.

$$ref attribute

The $$ref attribute on an element whose component is lifted using fromClass

<Link2 href="https://www.youtube.com/watch?v=Rbm6GXllBiw"
       $$ref={elem => elem && elem.focus()}>
  {Rx.Observable.from([3, 2, 1, "Boom!"], Rx.Observable.interval(1000))}
</Link2>

does the same thing as the ordinary JSX ref attribute: JSX/React treats ref as a special case and it is not passed to components, so a special name had to be introduced for it.

Previous Work

xaret.js is a port of karet to use RxJS instead of KefirJS for embeding observables into React components. This library is based and isnpired by the work of @polytypic and @fiatjaf.

Read more about React Combinator at Calmm-js.

Tutorials

coming soon...