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-arbiter

v0.9.4

Published

Recall all your modules to extend your SPA dynamically at runtime.

Downloads

28

Readme

React Arbiter

Build Status npm Version GitHub Tag GitHub Issues

React Arbiter provides a sets of components and utilities to recall runtime extensions to your application and to stasis third-party components to avoid crashing your application.

:warning: Deprecated! Please use Piral instead.

Getting Started

You need to have Node with NPM installed. In your repository run

npm i react-arbiter

Recalling Modules

In the simplest case you want to just use the ArbiterRecall without any loading special rendering while loading. For this use

import { ArbiterRecall } from 'react-arbiter';

function createApi(moduleMeta) {
  //create here an API object for the respective module
  return {};
}

function fetchModules() {
  //get a list of the available modules, potentially with content
  return fetch('/your/modules');
}

const App = (
  <ArbiterRecall createApi={createApi} fetchModules={fetchModules}>
    <YourComponent />
  </ArbiterRecall>
);

A module comes with the following interface:

interface ArbiterModuleMetadata {
  version: string;
  name: string;
  dependencies: {
    [name: string]: string;
  };
  content?: string;
  link?: string;
  hash: string;
}

This is similar to what the package.json looks like, however, containing three new elements: A hash representing the module, and either a link to the module's content (link) or the content directly (content).

Component Stasis

React Arbiter comes with a stasis field for third-party components. This is essentially just an error boundary that helps to prevent any external components destroying the whole application when crashing.

const ProtectedComponent = (
  <ArbiterStasis onError={e => console.error(e)}>
    <MyCrashingComponent />
  </ArbiterStasis>
);

Furthermore, we can determine what to render when an error occurs:

const ProtectedComponent = (
  <ArbiterStasis renderError={e => <div>Display the error: {e.message}</div>}>
    <MyCrashingComponent />
  </ArbiterStasis>
);

There is also a HOC to combine the renderError with the component to put into a stasis field.

const MyStasis = withStasis(({ error, type }) => (
  <div>
    <h1>{type}</h1>
    <p>Display the error: {error.message}</p>
  </div>
));
const ProtectedComponent = (
  <MyStasis type="Example">
    <MyCrashingComponent />
  </MyStasis>
);

Besides the added error prop other props are being forwarded as expected (see, e.g., the type prop in the previous example).

Wrapping Components

React Arbiter also gives you some utilities for wrapping components. For ordinary React components that means just placing them in a stasis field, however, for non-React components (referred to foreign components) we also introduce a React wrapper that hosts a DOM node for carrying the foreign component.

const MyReactComponent = props => <div>{props.children}</div>;
MyReactComponent.displayName = 'MyReactComponent';

const MyForeignComponent = (element, props) => {
  element.innerHTML = '<b>Hello World!</b>';
};

const WrappedReactComponent = wrapComponent(MyReactComponent);
const WrappedForeignComponent = wrapComponent(MyForeignComponent);

Important: The wrapComponent only supports React SFCs if they have the displayName property properly set (see above). Otherwise, this helper function cannot distinguish between a foreign and a React component and will therefore choose the foreign component.

License

react-arbiter is released using the MIT license. For more information see the LICENSE file.