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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@guanghechen/observable

v7.0.1

Published

<header> <h1 align="center"> <a href="https://github.com/guanghechen/sora/tree/@guanghechen/[email protected]/packages/observable#readme">@guanghechen/observable</a> </h1> <div align="center"> <a href="https://www.npmjs.com/package/@guanghech

Readme

Observable pattern implementation with ticker functionality for reactive programming. Provides value change notification with optional delay debouncing and custom equality comparison.

Install

  • npm

    npm install --save @guanghechen/observable
  • yarn

    yarn add @guanghechen/observable

Usage

Basic Observable

import { Observable } from '@guanghechen/observable'
import { Subscriber } from '@guanghechen/subscriber'

const count = new Observable<number>(0)

const subscriber = new Subscriber({
  onNext: (newValue, oldValue) => {
    console.log(`Value changed from ${oldValue} to ${newValue}`)
  }
})

const unsubscribable = count.subscribe(subscriber)

count.next(1) // "Value changed from 0 to 1"
count.next(2) // "Value changed from 1 to 2"
count.next(2) // No notification (same value)

console.log(count.getSnapshot()) // 2

unsubscribable.unsubscribe()
count.dispose()

Observable with Custom Equality

import { Observable } from '@guanghechen/observable'
import { Subscriber } from '@guanghechen/subscriber'

interface IUser {
  id: number
  name: string
}

const user = new Observable<IUser>(
  { id: 1, name: 'John' },
  { equals: (a, b) => a.id === b.id }
)

const subscriber = new Subscriber<IUser>({
  onNext: (value) => console.log('User changed:', value)
})

user.subscribe(subscriber)

// This won't trigger notification (same id)
user.next({ id: 1, name: 'Jane' })

// This will trigger notification (different id)
user.next({ id: 2, name: 'Bob' })

// Force notification even if equal
user.next({ id: 2, name: 'Bob Updated' }, { force: true })

Observable with Delay (Debouncing)

import { Observable } from '@guanghechen/observable'
import { Subscriber } from '@guanghechen/subscriber'

// Debounce notifications by 100ms
const search = new Observable<string>('', { delay: 100 })

const subscriber = new Subscriber<string>({
  onNext: (value) => console.log('Search:', value)
})

search.subscribe(subscriber)

// Rapid updates - only the last value will be notified after 100ms
search.next('h')
search.next('he')
search.next('hel')
search.next('hell')
search.next('hello')
// Output after 100ms: "Search: hello"

Ticker

Ticker is a specialized observable that increments a counter value:

import { Observable, Ticker } from '@guanghechen/observable'
import { Subscriber } from '@guanghechen/subscriber'

const ticker = new Ticker({ start: 0, delay: 100 })

const subscriber = new Subscriber<number>({
  onNext: (tick) => console.log('Tick:', tick)
})

ticker.subscribe(subscriber)

ticker.tick() // Tick: 1
ticker.tick() // Tick: 2

// Observe other observables - ticker increments when they change
const name = new Observable<string>('John')
const unobservable = ticker.observe(name)

name.next('Jane') // Also triggers: Tick: 3

unobservable.unobserve()
ticker.dispose()

Reference