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

mobx-react-utils

v1.1.0

Published

Mobx react utilities

Downloads

83

Readme

mobx-react-utils

Utilities often needed for react-mobx development

npm

Install

npm i -S mobx-react-utils

Usage

@autoDispose

Decorate a function which return a disposer function, and automatically excute it when react component unmount

Type: method decorator

Context: React component class

Target: () => Disposer


    public componentDidMount(): void {
	    // listen the change of query and do action
	    this.loadStatsReaction();
	}

	@autoDispose
	public loadStatsReaction(): () => void {
		return reaction(() => this.query, () => {
			this.model.loadStats(this.query);
		}, {
			fireImmediately: true,
		});
	}

Packgen

Generate an infinite iterator from an input array

Type: Iterator factory

Context: any

Target: T[]

Produce: Iterable Iterator

const pages = [0 , 1 , 2];

const choicePack: IterableIterator<number> = packGen(pages);

Comparer

Sets of comparer for using with Array.sort function

Member:

// Sorters
aZComparer<string>
zAComparer<string>
INComparer<number>
NIComparer<number>

// Preset pack (generate with packgen)
numberPack
stringPack
export declare type Comparer<T> = (a: T, b: T) => number;
export declare function aZComparer(a: string, b: string): number;
export declare function zAComparer(a: string, b: string): number;
export declare function INComparer(a: number, b: number): number;
export declare function NIComparer(a: number, b: number): number;
export declare const stringPack: IterableIterator<typeof aZComparer | null>;
export declare const numberPack: IterableIterator<typeof INComparer | null>;
const pack1 = numberPack();
pack1.next().value === null // true
pack1.next().value === INComparer // true

copyFields

Shallow copy property from one object to another with simple typing

Type: function

Context: any

Target: object

Produce: mutation

const x: A;
const y: A;
copyFields<A>(x, y);

groupBy

Group array of object by one property value into another result object

Type: function

Context: any

Target: T[]

Produce: object

export interface IGroupByResult<T> {
    [key: string]: T[];
}
export declare function groupBy<T>(arrayInput: T[], key: keyof T): IGroupByResult<T>;

mergeClassName

Merge two css modules styles object into one by concatenate each field

export interface IStyles {
    [key: string]: string;
}
export declare function mergeClassName<T extends IStyles>(target: T, source?: Readonly<Partial<T>>): T;

notEmpty

Type guard T from undefined or null

export declare function notEmpty<T>(value: T | null | undefined): value is T;

License

Apache license 2.0