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

mutant-attachable

v1.0.2

Published

A utility for React components to easily subscribe to Mutant streams

Readme

mutant-attachable

yarn add mutant-attachable

Utilities functions to call in React component lifecycle hooks to setup observation of Mutant observables. Works even better with TypeScript, but also works with normal JavaScript.

What problem this package solves

Let's say you have some mutant observables and you pass them to a React component through props:

<MyComponent isBlue={computed([state.color], color => color === 'blue')}>

Your implementation looks like

class MyComponent extends Component {
    constructor(props) {
        super(props);
        this.state = {isBlue: false};
    }

    componentDidMount() {
        this.removeIsBlue = this.props.isBlue(val => {
            this.setState(prev => ({...prev, isBlue: val}));
        });
    }

    componentWillUnMount() {
        if (this.removeIsBlue) {
            this.removeIsBlue();
            this.removeIsBlue = undefined;
        }
    }

    // ...
}

That's just one observable, but what if you have many? Such tedious wiring just to get mutant prop foo automatically update the component state foo.

Usage

In JavaScript:

+import {attachMutant, detachMutant} from 'mutant-attachable';

 class MyComponent extends Component {
     constructor(props) {
         super(props);
         this.state = {isBlue: false};
+        this.watcherRemovers = {isBlue: null};
     }

     componentDidMount() {
+        attachMutant(this, 'isBlue');
     }

     componentWillUnMount() {
+        detachMutant(this, 'isBlue');
     }

    // ...
 }

In TypeScript:

+import {MutantAttachable, attachMutant, detachMutant} from 'mutant-attachable';

 // The MutantAttachable<NAMES> interface makes sure you wont make any typo
 // and that the provided NAMES match the props

-class MyComponent extends Component {
+class MyComponent extends Component implements MutantAttachable<'isBlue'> {
     constructor(props) {
         super(props);
+        this.state = {isBlue: false};
+        this.watcherRemovers = {isBlue: null};
     }

     componentDidMount() {
+        attachMutant(this, 'isBlue');
     }

     componentWillUnMount() {
+        detachMutant(this, 'isBlue');
     }

     // ...
 }

This tool becomes really useful once you have many mutant streams as props:

import {MutantAttachable, attachMutant, detachMutant} from 'mutant-attachable';

class MyComponent extends Component
    implements MutantAttachable<'isBlue' | 'name' | 'age' | 'imageUrl'> {

    constructor(props) {
        super(props);
        this.state = {isBlue: false, name: '', age: 0, imageUrl: ''};
        this.watcherRemovers = {isBlue: null, name: null, age: null, imageUrl: null};
    }

    componentDidMount() {
       attachMutant(this, 'isBlue');
       attachMutant(this, 'name');
       attachMutant(this, 'age');
       attachMutant(this, 'imageUrl');
    }

    componentWillUnMount() {
       detachMutant(this, 'isBlue');
       detachMutant(this, 'name');
       detachMutant(this, 'age');
       detachMutant(this, 'imageUrl');
    }

    // ...
}

API

MutantAttachable<'key1' | 'key2' | 'key3' | ...>

Use this TypeScript interface to make sure your React component can observe mutant streams correctly in order to update the component state.

Your React component should implement MutantAttachable<KEYSGOHERE> where KEYSGOHERE should be a list of mutant streams that will be observed. E.g. implement MutantAttachable<'name' | 'imageUrl'> Notice that this list of strings is separated by |.

attachMutant(instance, name, update?)

Attach a mutant stream to a React component.

Call this function in componentDidMount in order to attach the mutant stream that exists in the props. The values from the stream will be written to the React component state.

  • param instance: React component instance (this keyword, when inside componentDidMount)
  • param name: string that identifies the mutant stream to be attached.
  • param update: optional function that takes a value (from the mutant stream) and can call this.setState to update the React component state.

detachMutant(instance, name)

Detach a mutant stream from a React component.

Call this function in componentWillUnmount in order to detach the mutant stream from the React component.

  • param instance: React component instance (this keyword, when inside componentWillUnmount)
  • param name: string that identifies the mutant stream to be attached.