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

@uwu/ash

v1.1.0

Published

A TS framework that looks vagely like Elm from a distance.

Downloads

2

Readme

Ash

A JS/TS UI framework that looks vaguely like Elm from a distance.

Ash believes in one simple thing: the UI code need not be concerned with the precise detail of updating your state. The UI should simply say what has happened, and other code can deal with the specifics.

A brief intro via example

Ash is component-based, and you create an example component like this:

const CounterBtn = ash.comp({
    state: (props) => props.init || 1,
    updates: {
        incr: (props, state, amt = 1) => state + amt
    },
    render: (props, state, update) =>
        ash.html`<button onClick=${() => update.incr(3)}>
            The count is ${state}
        </button>`
});

document.querySelector("#root").append(ash.html`<${CounterBtn} />`);

Every component has a state. The initial value of this is set in the component definition.

You output your UI as DOM nodes, but the ash.html helper allows you to easily build DOM nodes, and template in useful things. It is using developit/htm, by the way!!

Ash will not update parents of your component when they are re-rendered.

Each component has a set of updates that you can run. These directly operate on the state, based on what was passed to it. They produce the new state which the UI is rendered from.

Stateless components and direct mutations

Stateless components are simpler. They are built either by omitting state and updates, or just passing a function to ash.comp.

const OneSimpleComponent = ash.comp({
    render: (props) => ash.html`<div>Hi!</div>`
});

const AnotherSimpleComponent = ash.comp((props) => ash.html`<div>Bye!</div>`);

The upside of Ash is that it lets you decouple your state updating logic from the places where those updates are triggered. Sometimes you really don't need this, so in those cases, you can use the secret fourth function passed to your render func.

If your state is an object, you can mutate it, then just call mutate, or you can, for any state type, pass the new one to mutate.

This will replace the state and re-render directly.

const SimpleComponent = ash.comp({
    state: (props) => 0,
    render: (props, state, _, mutate) =>
        ash.html`<button onClick=${() => mutate(state + 1)}>${state}</button>`
})

Worth noting that Ash knows the difference between mutate() and mutate(undefined), so you can use undefined as a state safely, without fear of Ash assuming that you've already mutated an object state :)

This imperative programming style may be more comfortable to some, and is nice for simple components, but removes the benefit of keeping your precise update logic away from the view.

mount and unmount hooks

The mount and unmount hooks in Ash components are both passed the same arguments as render.

Calling them during a render looks like this:

  • If mounted, call unmount(), else do nothing
  • Call render() to get the new dom nodes to use
  • If mounted, remove the old nodes from the document
  • Add new node to the document
  • Call mount()

So when a rerender happens, unmount will be hit first, then render, then mount.

You can also return a function from mount() to call it before the next unmount() automatically. This will only happen the next time, and is optional. It is useful for cleaning up subscriptions, etc.

Be careful, these are very noisy functions, adding handlers here handling, eg, mouse events is an easy way to make performance issues.