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

@westbrookdaniel/palm

v0.6.0

Published

Small UI library designed for islands

Downloads

5

Readme

@westbrookdaniel/palm

Small UI library designed for islands.

Build reactive islands in < 200 bytes!

In a similar model to react, this rendering library is "fast enough" but for this tradeof it gains an very small bundle size. It does this through instead of diffing or another method, I just destroy and rebuild the whole tree every time. This is appropriate for Island architecture since the node trees are going to be small anyway. Beyond the different approach, the library maintains the minimum needed to do reactive islands; state (useState) and a way to run things when its dependencies change (useEffect). On the journey for a slim size, I've also chosen to omit any form of sanitisation, so you need to do that yourself. Of course, being designed for islands, you can also run multiple instances of the app at the same time mounted against different elements.

As you can tell, the library follows a simliar convention to react where hooks (use) must be used inside of components and be called in a consitent order.

Both JSX and tagged template literals are supported.

There is also a extra small version at /dist/index.min.js which is minified (unlike the rest of the modules, since it's expected you will use a bundler), although it does not include JSX support. This version also includes the global Palm with the properties renderHtml, useEffect, useState and html, so you can easily use this without a bundler.

Try it out with https://unpkg.com/@westbrookdaniel/palm/dist/index.min.js (< 100 bytes)

Otherwise install the package normally using your package manager (e.g. npm install @westbrookdaniel/palm)

If using JSX, add "jsx": "react-jsx", "jsxImportSource": "@westbrookdaniel/palm" to your tsconfig.json.

Example Code

import {
  useState,
  useEffect,
  render,
  html,
  render,
  renderHtml,
} from "@westbrookdaniel/palm";

function App() {
  const [count, setCount] = useState(0);

  const dec = () => setCount(count - 1);
  const inc = () => setCount(count + 1);

  return (
    <>
      <h1>Count: {count}</h1>
      <button onClick={dec}>Decrement</button>
      <button onClick={inc}>Increment</button>
      <TaggedTemplateApp />
    </>
  );
}

render(App, document.getElementById("app")!);

function TaggedTemplateApp() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    console.log("Only once!");
  }, []);

  const dec = () => setCount(count - 1);
  const inc = () => setCount(count + 1);

  return html`
    <h1>Count: ${count}</h1>
    <button onClick=${dec}>Decrement</button>
    <button onClick=${inc}>Increment</button>
  `;
}

renderHtml(TaggedTemplateApp, document.getElementById("taggedTemplateApp")!);

renderToString

There is also another function exported called renderToString which can be used for rendering an component to string. This is particularly useful for server side rendering (SSR). It works with both JSX and tagged template literals.

import { renderToString } from "@westbrookdaniel/palm";

renderToString(() => <div></div>); // '<div></div>'