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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mapsignal

v2.0.3

Published

A specialization of Angular's signals for Map objects.

Readme

mapSignal

MapSignal is a specialization of Angular's Signals to Map objects.

Rationale

The purpose of a signal is to reliably warn its dependents (computed signals referencing it) when its value has changed. It does so by watching for calls to its .set and .update methods.

Notifying the signal's value's mutation

This causes an issue when handling mutable objects as the signal's value, since mutating the object can be done without the signal object's awareness:

const a = signal(new Map<string, string>());
const b = computed(() => a().get("k"));
const o = signal({"p": "v"});
const q = computed(() => o().p);

...

a().set("k", "valu"); // a doesn't catch that its value is changed, b isn't updated.
o().p = "valu"; // same

For POJOs, a solution could be to turn all writeable properties into signals themselves, but this solution doesn't work for arrays, Sets, or Maps.
For Maps, that can be fixed by calling a.set(a()), thus signifying to the signal that its value may have changed, but you need to have the consistency of doing that everywhere in your code.
This module ensures that it's done when it needs to.

Equality checks are not reliable

Whenever the .set or .update methods are called, the signal does not immediately considers itself as obsolete, as it first performs an equality check between the old and the new values.
When using POJOs or Maps, an issue is that this equality check is done using object identity (Object.is) by default ; but even if a key-value equality check were done, Angular would compare the mutated object with itself, since that's the value passed to the signal's .set method. Thus mutations of the object still go unnoticed even with the solution above.
This issue is fixed in this package by providing an always-false equality function by default, which means that a refresh is triggered whenever this package decides it instead of leaving the matter for Angular to decide.

API

This module provides a new creator function, mapSignal, and an interface for the returned value.

function mapSignal<K, V>(initialValue?: Map<K, V>, options?): MapSignal<K, V>

  • initialValue defaults to a new empty map, as opposed to the base signal constructor where the parameter is required.

  • options is the same as taken by the native signal, except that the equal key is an equality function for the map's values, of type V, rather than the signal's value, of type Map<K, V>. It is used when the set method is called, to determine whether to refresh the signal or not.

interface MapSignal<K, V>

  • You can see this as the signal version of a final/readonly mutable variable. Calling the signal returns a ReadonlyMap<K, V>, which (as the type implies) should never be mutated by itself.

  • The MapSignal.set and MapSignal.delete methods match the Map.set and Map.delete methods, respectively, in all aspects except that they do not return a value.
    Warning : do not confuse Map.set with WriteableSignal.set : the former takes two parameters, a key and a value, when the latter takes only one, the signal's value. There is no equivalent to the latter, no way to replace the map object as a whole.

  • MapSignal.asReadonly is similar to WriteableSignal.asReadonly, returning a true Signal<ReadonlyMap<K, V>> linking to the same map.