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

@frostime/solid-signal-ref

v2.0.0

Published

A utility for SolidJS, to make it easier to manage signals in components

Downloads

5

Readme

@frostime/solid-signal-ref

中文文档

This is a small utility to simplify the use of signals in solidjs. It allows for easier access and modification of signals.

Installation

npm install @frostime/solid-signal-ref

Usage

Import the useSignalRef function from the package:

import { useSignalRef } from '@frostime/solid-signal-ref';
  1. Create a signal
const count = useSignalRef<number>(0);
  1. Access the signal's value: two ways
count(); // Accessor style access
count.value; // Vue style access
count.signal(); // Use count.signal to directly access the signal object itself
  1. Modify the signal's value
count(1); // Pass in a new value
count.value = 2;  // Vue style modification
count.update(3);  // Use count.update equivalent to directly accessing the setSignal function
count.update(v => v * 2);
  1. Derived signal
// Equivalent to const doubled = () => count() * 2;
const doubled = count.derived(c => c * 2);

<p>Doubled count: {doubled()}</p>

Usage Example

function App() {
  const count = useSignalRef(0);

  const odd = () => (count() % 2 === 1) ? 'Yes' : 'No';
  const wordCount = count.derived(c => `Word count: ${c.toString().length}`)
  const numberStr = createMemo(() => {
    const abs = Math.abs(count());
    if (abs < 1000) {
      return abs.toString();
    } else if (abs < 1000000) {
      return (abs / 1000).toFixed(1) + 'k';
    } else {
      return (abs / 1000000).toFixed(1) + 'M';
    }
  });

  return (
    <>
      <div class="card">
        <button onClick={() => count((count() + 1))}>
          {count()} + 1
        </button>
        <button onClick={() => { count.value -= 1 }}>
          {count.value} - 1
        </button>
        <button onClick={() => { count.update((c: number) => 10 * c) }}>
          {count.value} * 10
        </button>
        <button onClick={() => { count.value /= 10 }}>
          {count.value} / 10
        </button>
        <p>
          Is count odd? {odd()}; {wordCount()}; {numberStr()}
        </p>
      </div>
    </>
  )
}