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

@matchlighter/fetcher

v0.6.5

Published

Awesome declarative data "fetchers" for Class-Based React Components.

Downloads

56

Readme

@matchlighter/fetcher

Awesome declarative data "fetchers" for Class-Based React Components.

Fetcher leverages MobX and @matchlighter/meta_components to provide a clean, effective API.

Usage

NB: Be sure to decorate your Class Components with @with_meta_components from @matchlighter/meta_components.

@fetched(func: (params) => data, options?: { ... })

A basic fetcher that executes an async function when params change and sets the return value to the property. The basic fetcher provides options for debouncing, throttling, polling and more. See the Type definitions for the options parameter for details.

@api_fetched(url, transformer?: (response) => data, options?: { ... })

Fetcher includes a pre-built @api_fetched decorator that leverages Axios. @api_fetched provides most of the same options that @fetched does.

It may be used by decorating an accessor like so:

@with_meta_components // Note that this decoration is required. If using MobX, place it _above_ `@observer`.
class SomeComponent extends Component {
    @api_fetched("api/v1/some_class/:id")
    accessor api_result: ApiResultType;
}

It will automatically resolve :parameters in the URL string against a configurable set of sources. The default resolution order is as follows:

  • this
  • this.props
  • this.props.match.params (Intended for use with React Router)
  • config.token_context

Configuration

@api_fetched can be configured in a number of ways. This can be done like so:

import { config } from '@matchlighter/fetcher'
config.api.token_context = {}; // Provide a global data store for use when resolving `:parameter`s
config.api.backend = AxiosInstance; // Set the Axios Instance for use when making API calls
config.api.transform_response = (response) => transform_response; // Set a default response transformer

// Configure default options for `@api_fetched` Fetchers
config.api.defaults = {
    // Any Option that can be passed to Axios can be included here as well.
    ...AxiosRequestConfig,

    // Set the Request method that should be used
    method: 'GET',

    /* Action to take when a URL can't resolve all of its tokens.
     * - 'skip' - Don't make the request
     * - 'error' - Throw and Error
     * - 'continue' - Make the request anyway, without substituting the token
     * - May also be a function: (missingTokens: string[]) => MissingTokenAction
     */
    missingTokens: 'skip',

    /* May be a list of sources for token resolution, or a custom function.
     * Function Signature: (token: string, extraParams, component) => string
     * If an array is supplied, it may contain any of the following values:
     * - `this` - The Component instance
     * - `$token_context` - The global config.api.token_context object
     * - `$params` - Fetcher-local Params
     * - `$react_props` - React Props Hash
     * - `$react_state` - React State Hash
     * - `$route_params` - React Router route params
     */
    resolveTokens: ['this', '$react_props', '$route_params', '$token_context'],
}