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

vsx

v0.8.0

Published

Write vanilla JavaScript in JSX.

Downloads

72

Readme

vsx

Write vanilla JavaScript in JSX.

Getting Started

  1. Install via your preferred node modules manager or CDN.
  2. With TypeScript, add these options in your tsconfig
    "jsx":"react",
    "jsxFactory": "VSX.createElement",
    "jsxFragmentFactory": "VSX.createFragment",

Design

If you think of DOM as computer memory, then an element is a variable. To update a variable (element), you access it via a pointer (id property). This is called state. State refers to an element with a unique id. Elements without id are regular XML markup.

const [count, setCount] = createState(0);

Since there is no virtual DOM or proxy magic, number needs to be inserted in the markup so that a unique id can be generated which is referenced by setCount function.

<>
  <button onClick={setCount(count().value - 1)}>-</button>
  <div>{count}</div>
  <button onClick={setCount(count().value + 1)}>+</button>
</>

A component is a way to write markup such that it abstracts away the document.createElement function calls.

An effect tracks changes to certain elements via the MutationObserver API. Effects should be used to make calls to external systems such as window.localStorage or network requests.

Here's the complete example of a counter:

import VSX, { createEffect, createState } from "vsx";

const Counter = () => {
    const [count, setCount] = createState(0);

    createEffect(() => {
        localStorage.setItem("count", count);
    }, [count]);

    return (
        <>
            <button
                onClick={() => setCount(count().value - 1 )}
            >
                -
            </button>
            <span>
                {count}
            </span>
            <button
                onClick={() => setCount(count().value + 1 )}
            >
                +
            </button>
        </>
    )
}

Contributing

  • Conventional commits are enforced.
  • Pull requests are squashed and merged onto main branch.
  • Lint your code before commiting your change.
  • Add tests whenever possible.

Inspiration/References

Contributing

To open a bug report or to add a feature request, open a PR and edit Roadmap in README.md. Once that bug is resolved/feature is implemented, it will be moved to the CHANGELOG.md.

Roadmap

  • Abstract out boilerplate not complexity. If the complexity is changed, people have to change their mental model of how it works.
  • Provide better developer experience such as throw errors when common mistakes have been made. For example: throw error when props have been added to a fragment (since the fragment is removed after transpiling.
  • Maybe throw an error or display warnings if components are missing certain accessibility features/standards.
  • No virtual DOM so its performance depends on the browser's performance.

Bugs

Features

  • [x] createElement
  • [x] createFragment
  • [x] createState
  • [x] createEffect
  • [ ] createRouter
  • [ ] Use Proxy for State object to allow React like state changes
  • [ ] Pass special children prop into components
  • [ ] Add support for arrays

Chores

  • [ ] Add end to end testing
  • [ ] Explore tagged templates
  • [ ] Move releases information to CHANGELOG.md
  • [ ] Might have to add custom tsconfigs for different bundlers

License

MIT