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

@solid-primitives/static-store

v0.0.8

Published

Primitives for creating small reactive objects that doesn't change their shape over time - don't need a proxy wrapper.

Downloads

181,285

Readme

@solid-primitives/static-store

turborepo size version stage

Primitives for creating small reactive objects that doesn't change their shape over time - don't need a proxy wrapper.

Installation

npm install @solid-primitives/static-store
# or
yarn add @solid-primitives/static-store
# or
pnpm add @solid-primitives/static-store

createStaticStore

Creates read-only object that is shallowly reactive — only reactive on its first level and for the enumerable properties specified in the initial value — and a setter. It behaves similarly to createStore, but with limited features to keep it simple and performant. Designed to be used for reactive objects with static keys and dynamic values, like reactive Event State, location, etc.

How to use it

It takes a single argument - an initial value. It returns a tuple with the store object and a setter function.

import { createStaticStore } from "@solid-primitives/static-store";

const [size, setSize] = createStaticStore({ width: 0, height: 0 });

createEffect(() => {
  // both of these are separate signals, that can be listened to independently
  console.log(size.width, size.height);
});

// changing the property will trigger observers of that property only
setSize("width", 100);

el.addEventListener("resize", () => {
  // passed object will get merged with the existing store
  setSize({ width: el.offsetWidth, height: el.offsetHeight });
});

// adding a new property will NOT work
// the shape of the store is static
setSize("new-property", "value");

createDerivedStaticStore

A derived version of the createStaticStore. It will use the update function to derive the value of the store. It will only update when the dependencies of the update function change.

How to use it

It works similarly to the createMemo primitive and it takes the same arguments, but it returns a reactive object rather than an accessor function.

// source
const [size, setSize] = createSignal({ width: 0, height: 0 });

const store = createDerivedStaticStore(size);

createEffect(() => {
  // both of these are separate signals, that can be listened to independently
  console.log(store.width, store.height);
});

el.addEventListener("resize", () => {
  // only the changed properties that changed will trigger their observers
  setSize(p => ({ ...p, height: el.offsetHeight }));
});

createHydratableStaticStore

A "hydratable" version of the createStaticStore - it will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete.

Warning This primitive version is experimental, and mostly used internally by other primitives. It is not recommended to use it directly.

import { createHydratableStaticStore } from "@solid-primitives/static-store";

// reads from the DOM
const getSize = () => ({ width: el.offsetWidth, height: el.offsetHeight });

const [size, setSize] = createHydratableStaticStore(
  // server fallback value
  { width: 0, height: 0 },
  // update function (called onMount)
  () => {
    el.addEventListener("resize", () => setSize(getSize()));
    return getSize();
  },
);

createEffect(() => {
  console.log(size.width, size.height);
});

Changelog

See CHANGELOG.md