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

@yarljs/hoc

v1.0.2

Published

Higher Order React Components

Downloads

1

Readme

hoc

Higher Order React Components

install

yarn install @yarljs/hoc

Usage

Fetchable

Fetchable is a HOC which maps a fetch action to a component. It is used to handle a common pattern when pulling down async data:

Start->Loading
Loading->Data
Loading->Error

Fetchable takes a @yarljs/fetch Redux action and two optional parameters to forward to the action invoke: params, and transform, which map input and output data from the fetch request respectively. The resulting React Component can then be given components for Data, Loading, and Error states:


const Container = Fetchable(
  yarlFetch.fetching("http://localhost:8081/chuck/jokes/categories",
      "getChuckStuff",
      {method: "GET"}
    ),
  {some: "params"}, undefined)


const TestData = ({data}) => {
  return (
    <div>
      Some Data
    </div>
  );
}

const TestError = ({error}) => {
  return (
    <div>
      Uh Oh: {error.toString()}
    </div>
  );
}

const TestLoading = ({loading}) => {
  return (
    <div>
      Loading...
    </div>
  );
}

const Root = () => {
  return (
    <Provider store={store}>
      <Container
        Data={TestData}
        Loader={TestLoader}
        Error={TestError}
      />
    </Provider>
  );
}

Default Render

If no components are passed to the Resulting Container, default html will be generated for the result of the query. This can be useful for rapid, and can even work in production if you intend to render content that doesn't need extensive user interaction. The Default renderer works by inspecting the shape of the data param at runtime, and generating sensible divs and css class names. For Example, a query named justiceleague which returned a simple list of superhero names would generate the following html:

<div className="justiceleague container">
  <div class="justiceleague data container">
    <ul class="justiceleague data list">
      <li class="justiceleague data item">Superman</li>
      <li class="justiceleague data item">Batman</li>
    </ul>
  </div>
</div>

Error and Loading states produce a similar layout.

This system is particularly useful for APIs described by systems like JSONAPI, Swagger, and GraphQL, where the Model describing the shape of the JSON data leads to meaningful names for data fields. While such a system may seem a regression to Web 1.0 style development, there is an important distinction: these classic systems rendered content on the sever. Combined with a simple HTTP proxy, the autorenderer can aggregate data from multiple backends, leaving only styling to the user.

Caveats

  • Currently the default renderer produces HTML, which means ReactNative apps can't make use of such a system. While the XML itself is easily replaceable with the default ReactNative components, more work will be needed to cascade styling down to components, as ReactNative has no support for traditional CSS.