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

observ-set

v1.0.2

Published

A Set like structure that's observable

Downloads

17

Readme

observ-set

A Set like structure that's observable

Install

npm install observ-set

Usage

var observSet = require('observ-set')
var observ = require('observ')
var isObserv = require('is-observ')

var set = observSet([{id: 1}, {id: 2}], function (obj, rawObj) {
  return [isObserv(rawObj), obj.id].join()
})

set(function onChange (state) {
  console.log('changed!')
})

set.add({id: 3})
set.delete({id: 2})
set.add(observ({id: 4}))

set.transaction(function (rawSet) {
  set.add({id: 2})
  set.add({id: 6})
  set.delete({id: 1})
})

// Transactional as well
set.forEach(function (value, valueCopy, rawSet) {
  if (value.id < 5) rawSet.delete(value)
})

API

new ObservSet([array], [hashFunction])

Creates a new ObservSet, with initial data obtained from array. hashFunction(value, rawValue) defines how the identity of objects is determined. value is the evaluated value, which might be the contents of another observ or a computed function. rawValue is whatever is passed to ObservSet. Note that hashFunction should return a primitive value, in most cases, if values are to be compared properly. Can also be called without the new keyword.

set()

Standard Observ interface. Returns a copy of the values in the set, as an array.

set(onChange)

Standard Observ interface. Calls onChange(values) with a copy of the values contained in the set, as an array.

set.set(array)

Standard Observ interface. Applies the hashFunction to values of array and overwrites the set with the new values, notifying all listeners.

set.add(value)

Applies hashFunction to value and adds the value if in the set, notifying all listeners if a value was added.

set.clear()

Clears the set and notifies all listeners.

set.delete(value)

Applies hashFunction to value and deletes the value if in the set, notifying all listeners if a value was deleted.

set.entries()

Returns an iterator with [value, value] entries, from a copy of the values contained in the set.

set.forEach(callback, [thisArg])

Starts a transaction around callback(value, value, rawSet), allowing you to modify rawSet and notify all listeners if any changes are made.

set.has(value)

Applies hashFunction to value and returns a Boolean whether the values is contained in the set.

set.values()

Returns an iterator from a copy of the values contained in the set.

set.transaction(callback)

callback(rawSet) is passed a Set-like object that you can safely mutate without notifying listeners before the transaction is over. If no mutations are made, the listeners will not be notified. Transactions can be canceled by returning false.

License

ISC