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

dubc-ds-base

v1.0.2

Published

Base class for observable data structures.

Downloads

12

Readme

dubc-ds-base

Provides the base class for observable data structures.

DSEvent

The data structures provided by dubc-ds are observable, meaning they can broadcast changes made to them to interested parties. Such changes are represented by the DSEvent interface, which consists of three fields:

  • cleared: If the entire data structure is emptied of elements, this field is set to the number of items in the data structure that were cleared. In that case, removed will not be present. This field will contain the number 0 when you add a listener to a data structure that's empty.
  • removed: An iterable of elements that were removed, as well as the index they were removed from (if the data structure is indexed.)
  • added: An iterable of elements that were added, as well as the index they were added at (if the data structure is indexed.) If you add th

It is possible for both removed and added to be present in the same event. In that case, a listener should process the removed iterable first, and then process the added iterable.

It's also possible for both cleared and added to be present in the same event. That occurs during bulk operations that necessarily alter the entire data structure, such as sorting an array.

Implementing an Observable Data Structure

Here's a simple example of an observable data structure that's just a thin wrapper around the native Set class:

import { Base } from "dubc-ds-base"

export class MySet extends Base {

  private set = new Set<number>()

  get size() {
    // We just return the native set's size.
    return this.set.size
  }

  [Symbol.iterator]() {
    // We can also just use the native set's iterators.
    return this.set[Symbol.iterator]()
  }

  add(n:number) {
    // An observable data structure should NEVER fire
    // an event if the data structure didn't actually change.
    if (this.set.has(n)) return
    // Make the change.
    this.set.add(n)
    // Fire the event to notify observers about the change.
    // Since we know the native set will append the new element
    // to the end of the iteration order, we can set the `at`
    // field of the event.
    this.fire({added:{items:[n], at:set.size - 1}})
  }

  delete(n:number) {
    // Again, NEVER fire an event if we didn't change anything.
    if (!this.set.has(n)) return
    // Make the change.
    this.set.delete(n)
    // Fire the event. Note that we don't set the `at` field here,
    // because we don't know it. That's OK!
    this.fire({removed:{items:[n]}})
  }

  clear() {
    // Yet again, NEVER fire an event if there's no actual change.
    const sz = this.set.size
    if (sz === 0) return
    // Make the change.
    this.set.clear()
    // Fire the event.
    this.fire({cleared:sz})
  }
}

The rule-of-thumb is that if you can set the at field in an event, then you should set the at field for that event.