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

catwalk

v0.1.0

Published

A framework for building web apps around structured data models

Downloads

6

Readme

Catwalk

Catwalk is a framework for JavaScript web apps that need to present a UI for managing complex structured data.

The catwalk package provides the model layer of the framework. In Catwalk, a model is a JavaScript class with a set of fields defined on it, which may be simple values such as strings or integers, or data structures such as arrays. Fields can have validation applied, and model state can be serialised and deserialised to and from JSON. Most importantly, each field provides a 'change' event that a UI component can listen to, allowing the UI to be efficiently kept in sync with the model.

See also catwalk-ui, which provides the UI layer.

Installation

npm install catwalk

A simple example

import { Model, fields } from 'catwalk';

class Rectangle extends Model([
    new fields.IntegerField('width', {min: 1, max: 1000}),
    new fields.IntegerField('height', {min: 1, max: 1000}),
    new fields.ValueField('color'),
]) {
    getArea() {
        return this.width * this.height;
    }
}

const rect = new Rectangle({width: 320, height: 200, color: 'red'});
rect.on('changeWidth', (w) => console.log('width is now', w));
rect.width = 640;

Why not React?

Catwalk and React follow broadly the same principles: your UI layer is a window onto a data model, and when the state of that data model changes, the UI has to change to reflect that state change. In React, the standard way of working is for a UI component to implement a 'render' method that generates the HTML representation for the new state in full; React then uses its internal magic to only update the parts of the DOM that have changed from the previous state.

This is less ideal when the UI component is a data grid managing potentially hundreds of data values, and changes are frequent - a change to a single value means that the HTML for the entire grid structure has to be generated, and then React has to scan though it to find the one item that has changed. These internal optimisations in React do at least ensure that we don't need to rebuild the browser DOM on every change - but to anyone familiar with O(n) notation, this still feels Wrong. Nothing should ever have to loop over an array just to update a single item.

In Catwalk, changing one item in an array will trigger a change event that the UI layer can respond to efficiently. In short - if you find that React has too much magic, Catwalk might be for you.