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

@elucidata/pulse

v1.0.6

Published

Microscopic signals with automatic dependency tracking.

Downloads

479

Readme

Pulse

Microscopic signals with automatic dependency tracking.

Pulse signals are straightforward containers for values—no magic, no proxies, no weird tricks. They hold anything you throw at them: scalars, objects, DOM elements, functions, classes, instances... Whatever.

No need to worry about tracking dependencies in your computed values or effects—Pulse handles that automatically.

Minify+gzips to < 2kB for core+utils.

At its core it's a simple API:

declare function signal<T>(intialValue: T): Signal<T>
declare function computed<T>(worker: () => T): Computed<T>
declare function effect(worker: () => void): Effect
declare function batch(worker: () => void): void

declare class Signal<T> {
  readonly id: string
  peek(): T
  get: () => T
  set(newValue: T, forceNotify?: boolean): boolean
  subscribe(listener: (newValue: T) => void): Effect
  dispose: () => void
}
declare class Computed<T> {
  readonly id: string
  peek(): T
  get: () => T
  subscribe(listener: (newValue: T) => void): Effect
  dispose: () => void
}
declare class Effect {
  readonly id: string
  dispose: () => void
}

Usage

import { signal, computed, effect } from "@elucidata/pulse"

const counter = signal(0)
const doubled = computed(() => counter.get() * 2)

effect(() => {
  console.log("Counter:", counter.get(), "doubled:", doubled.get())
})

counter.set(1)

Installation

No dependencies or prerequisites other than a JS runtime. Bun is used for development. To install pulse:

bun install github:elucidata/pulse

Utilities

persistedSignal

declare function persistedSignal<T>(
  key: string,
  initialValue: T,
  options?: Partial<PersistedSignalOptions<T>>
): Signal<T>

interface PersistedSignalOptions<T> {
  storage: IStorage // defaults to globalThis.localStorage
  toStorage: (value: T) => string // defaults to JSON.stringify
  fromStorage: (value: string) => T // defaults to JSON.parse
}

interface IStorage {
  getItem(key: string): string | null
  setItem(key: string, value: string): void
}

Creates a signal that persists its value in storage (using localStorage by default). The value is serialized to a string before being stored and deserialized when retrieved. If storage is unavailable, a regular signal will be returned instead.

update

declare function update<T>(
  state: Signal<T>,
  updater: Merger<T> | Updater<T>,
  reportChanges?: boolean
): boolean | (keyof T)[]

type Merger<T> = Partial<T> | ((v: T) => Partial<T>)
type Updater<T> = Required<T> | ((v: T) => T)

Updates a signal with a new value or partial value. If a function is provided as the updater, it receives the current value and should return the updated value. If an object is provided, it will be merged with the current value. When reportChanges is set to true, the function returns an array of keys that were changed

How is this different than (fill in the blank)

KISS. Keep It Simple, Signals. Think of it like nanostores but with automatic dependency tracking. If you need fancier signals implementations check out:

  • Preact Signals
  • MobX
  • SolidJS

Contributing

We will happily review contributions from the community. To be eligible for merging into pulse, please follow these guidelines and project goals:

  • Keep it simple
  • Keep it small
  • Keep it fast
  • Err on the side of less code

License

Pulse is licensed under the MIT License.