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

react-avenger

v9.0.3

Published

react bindings for avenger

Downloads

72

Readme

What's this about

This repo exports three decorators (aka component enhancer functions, aka HOCs) providing component apis for avenger: queries, commands and loading.

queries

Import the factory as

import declareQueries from 'react-avenger/queries';

Create the decorator as

const queries = declareQueries(allQueries);
// where `allQueries` is a dictionary String -> Query, e.g.
// {user: Query({ ... }), post: Query({ ... })  }

Use the decorator as

@queries(['user', 'post'])
class MyComponent extends React.Component {
  render() {
    // `user` and `post` are passed as props as soon as they are ready (fetched).
    // `readyState` is passed as prop, containing meta-info for each declared query
    // and meta info for the whole component declaration.
    // examples:
    
    // `loading` for the whole decalration
    return this.props.readyState.loading ? null : <div>Ready!</div>
    
    // `loading` for a single query
    return this.props.readyState.user.loading ? null : <User user={this.props.user} />
    
    // just render if we have something
    return this.props.user ? <User user={this.props.user} />
  }
}

loading

In combination with @queries, lets you conditionally render your component, optionally in a layout including a "loader" component.

Import the factory as

import loadingFactory from 'react-avenger/loading';

Create the decorator as

const loading = loadingFactory({ ...config  })

Use as

@queries(['user', 'post'])
@loading
class MyComponent extends React.Component {}

loading configuration

loader: default is "no loader", meaning that your component won't show any loading indicator. It will, nontheless, render only when "ready" (i.e. all the declared queries are resolved to a value).

wrapper: default is <div />. Not of much use if you don't have a loader.

Examples

const loading = loadingFactory(); // no loader

const loading = loadingFactory({
  loader: <MyLoadingSpinnerComponent /> // show a custom loader
});

const loading = loadingFactory({
  wrapper: <div style={{ position: 'relative'  }} /> // wrap it in a relative wrapper
  loader: <MyAbsoluteOverlayLoadingSpinnerComponent /> // show a custom absolute overlay loader
});

commands

Import the factory as

import declareCommands from 'react-avenger/commands';

Create the decorator as

const queries = declareCommands(allCommands);
// where `allCommands` is a dictionary String -> Command, e.g.
// { doSaveUserProfile: Command({ ... }) }

Use the decorator as

@commands(['doSaveUserProfile'])
class MyComponent extends React.Component {
  render() {
    // `doSaveUserProfile` is passed as prop
    // example:
    
    return <div onClick={() => this.props.doSaveUserProfile({ profile })}></div>
  }
}

real world usage

The examples below should work by themselves, but in a real world project you might want to define and re-export a single queries, commands and loading decorator, to be used in component files.

For loading, you might need different styles & layout, so we typically do something like:

import loading from 'loading/fillFlexLoading'; // or `fillAbsoluteLoading`, or `tinyLoading`, etc.