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

reactive-signal

v2.0.1

Published

English | [简体中文](https://github.com/Tencent/omi/blob/master/packages/reactive-signal/README.CN.md)

Downloads

350

Readme

English | 简体中文

Reactive-Signal is a powerful library for creating reactive data in JavaScript. It provides a set of functions to create signals, computed signals, effects and batch updates. With this library, you can easily build reactive applications where components automatically update when data changes.

Features

  • Ultra-Lightweight: The library is incredibly tiny at just 0.6 KB.
  • Easy-to-Use API: A simple and intuitive API that makes it easy to get started with reactive programming in JavaScript.
  • Reactive Data: Easily create reactive data signals and computed signals to automatically update components when data changes.
  • Effects: Define side effects that automatically react to signal changes, making it simple to manage complex application logic.
  • Batch Updates: Efficiently batch multiple updates into a single update, reducing unnecessary re-renders and improving performance.
  • Component Management: Built-in functions to set and get active components, making it easy to integrate with your application's component system.
  • Flexible: Can be used with any JavaScript framework or library, or even in vanilla JavaScript projects.

Installation

npm install reactive-signal

Usage

import { signal, computed, effect, batch } from 'reactive-signal'

// Create a signal
const count = signal(0)

// Create a computed signal
const doubleCount = computed(() => count.value * 2)

// Create an effect
effect(() => {
  console.log(`Count: ${count.value}, Double Count: ${doubleCount.value}`)
})

// Update the count signal
count.value = 1  // logs: "Count: 1, Double Count: 2"

// Batch multiple updates
batch(() => {
  count.value = 2
  count.value = 3
})  // logs: "Count: 3, Double Count: 6"

API

signal(initialValue)

Creates a signal with an initial value.

const count = signal(0)
// Using peek to get the value of the signal without creating a dependency
count.peek() === count.value // true

const todos = signal([])
todos.value.push('Learn Reactive Programming')
// Using update to change the value of the signal and trigger dependency updates
todos.update()

computed(fn)

Creates a computed signal based on a function.

effect(fn)

Creates an effect based on a function.

batch(fn)

Batches multiple updates into a single update.

setActiveComponent(component, updateFnName)

Sets the active component.

  • component: Component - The component object to set as the active component.
  • updateFnName?: string - (Optional) The name of the function in the component to use for updates. If not provided, the default value is queuedUpdate.

clearActiveComponent()

Clear the active component.

getActiveComponent()

Returns the active component.

Inspired by

License

MIT © Tencent