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

geiger

v1.0.4

Published

Tiny (<100 SLOC), no-dependencies Flux implementation with store synchronization (waitFor) and Dependency Injection features

Downloads

5

Readme

Geiger, the unfancy tool that does the job

Tiny (<100 SLOC), no-dependencies Flux implementation with store synchronization (waitFor) and Dependency Injection features.

Leverages React's (0.13+) contexts for injecting dependencies automatically down the component tree.

For a basic implementation reference, have a look at Idiomatic React.

For a full-scale implementation reference, making use of multiple synchronized stores, have a look at Idiomatic React Chat.

About Geiger

  • Dependency injection: Services are injected in components, and so are relative to your application context, rather than being used as global services
  • No dispatcher: rather than a central/global dispatcher, Geiger uses events and promises to manage the action flow, and to ensure that interdependent stores handle actions cooperatively
  • Readable source code: the source code should be small enough to be readable, and so to serve as the primary source of documentation

Installation

$ npm install --save geiger

Usage

// main.js
'use strict';

import React from 'react/addons';

import { ContextFactory, Action, Store } from 'geiger';
import TodoList from './TodoList';

// The Context component (think "Dependency Injection Container")
const Context = ContextFactory({
    todostore: React.PropTypes.object.isRequired,
    todoactions: React.PropTypes.object.isRequired
});

// Actions; just relay to the store, but can be much thicker
const todoactions = new (class extends Action {
    add(...args) { this.emit('add', ...args); }
    remove(...args) { this.emit('remove', ...args); }
})();

// Store (Mutable)
const todostore = new (class extends Store {

    constructor(actions, todos = []) {
        super();

        this.todos = todos;

        // action handlers
        this.listen(actions, 'add', (todo) => { this.todos.push(todo); this.changed(); });
    }

    // Public API
    getAll() { return this.todos; }

})(todoactions, ['Todo One', 'Todo Two', 'Todo three']);

React.render(
    (<Context
        todostore={todostore}
        todoactions={todoactions}
        render={() => <TodoList />} />),
    document.body
);
//TodoList.js
'use strict';

import React from 'react/addons';

export default class TodoList extends React.Component {

    // declaring dependencies to inject; can be a subset of all the context
    static contextTypes = {
        todostore: React.PropTypes.object.isRequired,
        todoactions: React.PropTypes.object.isRequired
    };

    // watching store changes
    componentWillMount() {
        this.unwatch = [this.context.todostore.watch(this.forceUpdate.bind(this))];
    }

    // unwatching store changes
    componentWillUnmount() { this.unwatch.map(cbk => cbk()); }

    render() {
        const { todostore, todoactions } = this.context;

        return (
            <div>
                <h2>Todos</h2>

                <button onClick={() => todoactions.add('Another thing to do !')}>Add todo</button>

                <ul>
                    {todostore.getAll().map(todo => <li>{todo}</li>)}
                </ul>
            </div>
        );
    }
}

Store synchronization

To synchronize store reaction to actions, use the waitFor() method of the store.

'use strict';

import { Store } from 'geiger';

export default class StoreC extends Store {

    constructor({ actions, storea, storeb }) {
        super();

        this.listen(actions, 'createTodo', (todo) => {
            return this.waitFor([storea, storeb]).then(() => {
                doSomething(todo);
            });
        });
    }
}

In this example, waitFor() returns a promise that'll wait for all given stores to be idle, and that'll execute then when that happens. This promise has to be passed to Geiger (hence the return; this is asserted at runtime by Geiger, so no worries).

If you need to, you can waitFor() for stores that also waitFor() for other stores to complete their action handling.

Test

$ npm test

Licence

MIT.

Maintainer

@netgusto