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

mutablevalue

v1.0.0

Published

Handling dependencies on a changeable value

Downloads

5

Readme

MutableValue.js

Description

An implementation of a pattern of handling dependencies on a changeable value. It implies that the user of the value retrieves it the same way as the changes will be subsequently reported. In general there's two underpinning parts: declaring a dependency on the value by supplying a listener and reporting a change of the value to the specified listeners.

Usage

/******************[creating an instance]***********************/
var value = new MutableValue("initial value");

/********[getting the value and declaring a dependency]*********/
value.GetValue(function(value) { 
    alert(value); 
}, /*optional*/ "marker");
//passes the value to the callback now and any time 
//the value changes, if the third parameter is passed 
//and has a value of **true** the marker will be used 
//as a value of **this** to the given callback

/*******************[setting a new value]***********************/
value.SetValue("new value");
//changes the value and invokes each added callback
//with this value as the first argument

//******************[modifying the value]***********************/
value.ModifyValue(function(v) { return v + 1; });
//assigns the value to a call result of the passed function
//which accepts the current value as the first argument

//************[checking a value for correctness]****************/
value.OnAssigning(function(v) { if (v < 0) return false; });
//if one of these functions returns a value of **false**
//no more callbacks will be invoked on this assignment
//and the new value will not be assigned

//**************[adding a value preprocessor]*******************/
value.OnChange(function(newValue, currentValue) {
    if ( newValue < 0 ) return currentValue;
}, /*optional*/ "marker");
//a return of each of these functions 
//will be passed to the next one as the first argument
//a return of the last one will replace the new value
//these functions will be invoked after those
//associated with **OnAssigning()** method

/**[modifying the value before sending it to the dependencies]**/
value.OnReporting(function(filteredValue, initialValue) {
    return "["+filteredValue+"]";
});
//these functions form a value that will be actually reported 
//as one representing the underlying value 
//that itself will not be modified

/*[another way of getting the value and declaring a dependency]*/
var v = value.TraceValue(function(value) { 
    alert("["+value+"]"); 
}, "m");
//the value is returned as the current call result,
//a callback, if supplied, will be invoked on change later on
//the third parameter defines whether or not 
//to use the marker as a value of **this**

/********[manually invoking the process of reporting]***********/
value.PassValue("m");
//the first argument specifies the marker
//if it is omitted all associated listeners will be invoked

/********************[removing a callback]**********************/
value.Release("marker");
value.ReleaseAll();

/****[suspending and resuming the utilization of a callback]****/
value.Disconn("marker");
value.Connect("marker");
//if these methods are called without an argument
//actions will be applied to all callbacks