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

ivix

v0.1.0

Published

Javascript (TypeScript) state management library for ivi.

Downloads

3

Readme

ivix

Application state management library for ivi inspired by Redux.

ivi library provides a low level API that allows to build almost zero cost connect components, and ivix API is designed to get the most out of it, for example selector checking doesn't need any memory allocations when nothing is changed.

Current Status

Experimental.

Usage Example

import { createStore, selectData, connectComponent } from "ivix";
import { render, update, $h, Events } from "ivi";

const store = createStore(
    { counter: 0 },
    function (prev, action) {
        switch (action.type) {
            case "INCREMENT":
                return { ...prev, counter: prev.counter + 1 };
            case "DECREMENT":
                return { ...prev, counter: prev.counter - 1 };
        }
        return prev;
    },
    update,
);

function inc() { store.dispatch({ type: "INCREMENT" }); }
function dec() { store.dispatch({ type: "DECREMENT" }); }

function selectCounter(prev) {
    const counter = store.getState().counter;
    if (prev && prev.in === counter) {
        return prev;
    }
    return selectData(counter);
}

function CounterDisplay(counter) {
    return $h("div").children([
        counter,
        $h("button").events({ click: Events.onClick(() => { inc(); }) }).children("+1"),
        $h("button").events({ click: Events.onClick(() => { dec(); }) }).children("-1"),
    ]);
}

const $CounterDisplay = connectComponent(selectCounter, CounterDisplay);

render($CounterDisplay(), document.getElementById("app"));

API

Create Store

function createStore<T, U>(
    state: T,
    reducer: (prev: T, action: U) => T,
    onChange: () => void,
): Store<T, U>;

Connect

VNode factory constructors that connect selectors.

function connect<T, U, K>(
    select: (prev: SelectData<K, U> | null, props: null | T, context: Context) => SelectData<K, U>,
    render: (props: U, context: Context) => IVNode<any>,
): (props: null | T) => VNode<T>;

function connectComponent<T, U, K>(
    select: (prev: SelectData<K, U> | null, props: null | T, context: Context) => SelectData<K, U>,
    component: ComponentClass<U>,
): (props: null | T) => VNode<null | T>;

Selectors

Helper functions to write selectors.

By default, all selectors are memoized locally, with this helper functions it is possible to create selectors memoized globally, or somewhere else, for example in Context.

function selectData<T, U>(i: T, o?: U): SelectData<T, U>;

function memoizeSelector<T, U extends SelectData>(
    select: (prev: U | null, props: T, context: Context) => U,
    ref: (v?: U | null) => U | null,
): (prev: U | null, props: T, context: Context) => U;

function memoizeSelectorGlobally<T, U extends SelectData>(
    select: (prev: U | null, props: T, context: Context) => U,
): (prev: U | null, props: T, context: Context) => U;

Mutable Collections

Mutable collections are tiny wrappers around primitive javascript collections with a method that creates a new instance with the same items.

They can be used as an efficient way to modify collections and update references, so it is easy to detect when something is changed.

class MutableArray<T> {
    readonly items: T[];
    constructor(items: T[] = []);
    update(): MutableArray<T>;
}

class MutableSet<V> {
    readonly items: Set<V>;
    constructor(items: Set<V> = new Set<V>());
    update(): MutableSet<V>;
}

class MutableMap<K, V> {
    readonly items: Map<K, V>;
    constructor(items: Map<K, V> = new Map<K, V>());
    update(): MutableMap<K, V>;
}