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 🙏

© 2025 – Pkg Stats / Ryan Hefner

keflux

v0.0.1

Published

Flux workflow using Kefir's FRP streams

Readme

Keflux

Keflux is a library that allows to use event streams to build a Flux architecture in a front-end React app. It uses [Kefir][] for all FRP-related code, and as part of the library name.

Stores

Keflux promotes the concept of self-contained stores, each defining its data structure and the actions that are available to perform on it. Below is an example store for a todo-list app:

const TodoStore = Keflux.Store({

  create(stream) {
    return stream.
      filter((text) => text.trim().length > 0).
      map((text) => {
        const todo = Immutable.OrderedMap({
          id: uuid.v1(),
          text: text,
          completed: false,
        });
        return (data) => data.set(todo.get("id"), todo);
      });
  },

  updateText(stream) {
    return stream.
      filter((params) => params.text.trim().length > 0).
      map((params) => {
        return (data) => data.setIn([params.id, "text"], params.text);
      });
  },

  toggleComplete(stream) {
    return stream.map((todo) => {
      return (data) => data.setIn([todo.id, "completed"], !todo.completed);
    });
  },

  destroy(stream) {
    return stream.map((todo) => {
      return (data) => data.remove(todo.id);
    });
  },

  clearCompleted(stream) {
    return stream.map(() => {
      return (data) => data.filter((todo) => !todo.get('completed'));
    });
  },

  toggleAll(stream) {
    return stream.map((checked) => {
      return (data) => data.map((todo) => todo.set('completed', checked));
    });
  },

});

Each action method receives a stream of events, each event being an invocation by the app to trigger that particular action. These action methods can then transform this stream using traditional FRP functions (filter, map, etc.)

The resulting stream should issue a series of functions, that when applied to the underlying data structure, modifies it in a way consistent with the action invoked.

For more real-world-like examples, take a look to a couple of stores in the examples/ directory. Those are todo-list stores but with persistend storage (one to local storage, and the other to an ajax json api).

Understanding how it works

To better understand this concept, let's look in detail at the create action from the example above:

create(stream) {
  return stream.
    filter((text) => text.trim().length > 0).
    map((text) => {
      const todo = Immutable.OrderedMap({
        id: uuid.v1(),
        text: text,
        completed: false,
      });
      return (data) => data.set(todo.get("id"), todo);
    });
}

The stream received as argument above will emit a new value each time the app invokes this action on the store. The first thing the action does is filtering out those invocations made with an empty text, since we do not want to-do items whose text is an empty string.

Then the valid events (those with non-empty text) are mapped to a function that receives the underlying data structure of the store (an immutable map), and returns a copy of it, but with the new todo-item added to it.

The result is a new stream of functions, that when applied to the store's data structure, each add a new todo item to it, as requested by the app using this store. The store takes care of applying these functions to the underlying data structure, on each iteration of the stream processing.

Usage on a React.js app

Keflux stores expose a stream called changes, which emits a new value each time the underlying data structure changes as a result of triggering one of its actions.

So once stores are defined like it is described above, a React.js component can subcribe to the changes on this store, and update its state to match the store's data. This is shown in the following example:

const TodoApp = React.createClass({
  propTypes: {
    store: React.PropTypes.object,
  },

  getInitialState() {
    return {
      data: this.props.store.data,
    };
  },

  componentDidMount() {
    this.props.store.changes.onValue((data) => this.setState({data}));
  },

  render() {
    // ...
  },
});

There are plans to provide a mixin for components to easily declare that its state depends on one or more stores, as well as to take advantage of React.js' contexts to implicitly pass stores to child components.

What's next

This is a list of features that have not been explored or implemented yet.

  • How does error handling fits with this architecture.
  • Mixin for easing the access to stores/actions in components via React.js' contexts.
  • Registering callbacks to handle action completion.