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

iguazu-holocron

v1.8.2

Published

Loads holocron modules using iguazu

Downloads

40

Readme

npm

This loads Holocron modules using Iguazu, an asynchronous data flow solution for React/Redux applications.

📖 Table of Contents

🤹‍ Usage

Installation

yarn add iguazu iguazu-holocron

# or

npm install --save iguazu iguazu-holocron

Usage within your module

Use queryModule if you would like to render a Module as soon as its bundle is loaded.


import React from 'react';
import { connectAsync } from 'iguazu';
import { queryModule } from 'iguazu-holocron';

const MyModule = ({ loadStatus, MySubModule }) => {
  if (loadStatus.all === 'loading') {
    return <Loading />;
  }

  return (
    <div>
      <MySubModule />
    </div>
  );
};

const loadDataAsProps = ({ store: { dispatch } }) => ({
  MySubModule: () => dispatch(queryModule('my-sub-module')),
});

export default connectAsync({ loadDataAsProps })(MyModule);

Use queryModuleWithData if you would like to wait until a Module's Iguazu data dependencies are loaded to render. Any props that are necessary for the Module to decide what data to load should be passed as the second argument.

import React from 'react';
import { compose } from 'redux';
import { connectAsync } from 'iguazu';
import { queryModuleWithData } from 'iguazu-holocron';
import { connect } from 'react-redux';

const MyModule = ({ loadStatus, MySubModuleWithData, subModuleProp }) => {
  if (loadStatus.all === 'loading') {
    return <Loading />;
  }

  return (
    <div>
      <MySubModuleWithData subModuleProp={subModuleProp} />
    </div>
  );
};

const getSubModuleProps = (state, ownProps) => { /* return props to be passed to submodule */ };

const loadDataAsProps = ({ store: { dispatch, getState }, ownProps }) => ({
  MySubModuleWithData: () => dispatch(queryModuleWithData('my-sub-module-with-data', getSubModuleProps(getState(), ownProps))),
});

const mapStateToProps = (state, ownProps) => ({
  subModuleProps: getSubModuleProps(state, ownProps),
});

export default compose(
  connectAsync({ loadDataAsProps }),
  connect(mapStateToProps)
)(MyModule);

Sometimes a Module may fail to load. If that is the case the data returned from Iguazu Holocron will be an instance of EmptyModule. The helper function anyAreEmpty will tell you if any of the Modules you pass to it are an empty Module.

import React from 'react';
import { connectAsync } from 'iguazu';
import { queryModule, anyAreEmpty } from 'iguazu-holocron';

const MyModule = ({ loadStatus, SubModuleA, SubModuleB }) => {
  if (loadStatus.all === 'loading') {
    return <Loading />;
  }

  const pageFailedToLoad = anyAreEmpty(SubModuleA, SubModuleB);

  return pageFailedToLoad
    ? <LoadError />
    : (
      <div>
        <SubModuleA />
        <SubModuleB />
      </div>
    );
};

const loadDataAsProps = ({ store: { dispatch } }) => ({
  SubModuleA: () => dispatch(queryModule('sub-module-a')),
  SubModuleB: () => dispatch(queryModule('sub-module-b')),
});

export default connectAsync({ loadDataAsProps })(MyModule);

🎛️ API

queryModule

An Iguazu adapter for loading a Holocron module.

Arguments

| name | type | required | value | |---|---|---|---| | moduleName | String | true | The name of the Holocron module to load |

Usage

import { connectAsync } from 'iguazu';
import { queryModule } from 'iguazu-holocron';

const MyModule = ({ MyOtherModule }) => (
  <>
    {/* some jsx */}
    <MyOtherModule />
  </>
)

function loadDataAsProps({ store }) {
  return {
    MyOtherModule: () => store.dispatch(queryModule('my-module')),
  };
}

export default connectAsync({ loadDataAsProps })(MyModule);

queryModuleWithData

An Iguazu adapter for loading a Holocron module and its data (from the loaded module's own loadDataAsProps).

Arguments

| name | type | required | value | |---|---|---|---| | moduleName | String | true | The name of the Holocron module to load | | moduleProps | Object | true | Initial props to pass the module when loading |

Usage

import { connectAsync } from 'iguazu';
import { queryModuleWithData } from 'iguazu-holocron';

const MyModule = ({ MyOtherModule, someData }) => (
  <>
    {/* some jsx */}
    <MyOtherModule someData={someData} />
  </>
)

function loadDataAsProps({ store, ownProps }) {
  return {
    MyOtherModule: () => store.dispatch(
      queryModuleWithData('my-module', { someData: ownProps.someData })
    ),
  };
}

export default connectAsync({ loadDataAsProps })(MyModule);

isEmpty

isEmpty checks to see if the module queried has been loaded or if the module received in props is still the default empty component.

Arguments

| name | type | required | value | |---|---|---|---| | module | Function | true | A module that has been loaded by one of the above Iguazu adapters |

Usage

import { connectAsync } from 'iguazu';
import { queryModule, isEmpty } from 'iguazu-holocron';

const MyModule = ({ MyOtherModule }) => (
  <>
    {/* some jsx */}
    {isEmpty(MyOtherModule) ? <Spinner /> : <MyOtherModule />}
  </>
)

function loadDataAsProps({ store }) {
  return {
    MyOtherModule: () => store.dispatch(queryModule('my-module')),
  };
}

export default connectAsync({ loadDataAsProps })(MyModule);

anyAreEmpty

anyAreEmpty taks n arguments, all of which are Holocron modules loaded with one of the above Iguazu adapters. It is used to check if any modules in the argument list are still the default empty module.

Arguments

| name | type | required | value | |---|---|---|---| | module | Function | true | A module that has been loaded by one of the above Iguazu adapters |

Usage

import { connectAsync } from 'iguazu';
import { queryModule, anyAreEmpty } from 'iguazu-holocron';

const MyModule = ({ MyOtherModule, ThirdModule }) => (
  <>
    {/* some jsx */}
    { anyAreEmpty(MyOtherModule, ThirdModule) ?
      <Spinner /> :
      <MyOtherModule><ThirdModule/></MyOtherModule>
    }
  </>
)

function loadDataAsProps({ store }) {
  return {
    MyOtherModule: () => store.dispatch(queryModule('my-module')),
    ThirdModule: () => store.dispatch(queryModule('third-module')),
  };
}

export default connectAsync({ loadDataAsProps })(MyModule);

configureIguazuSSR

configureIguazuSSR is a helper for loading data on the server via Iguazu. It does not need to be called directly, but needs to be attached to the module as the static loadModuleData along with loadDataAsProps.

loadModuleData is a module lifecycle hook used by Holocron for data fetching during server side rendering.

Usage

import { connectAsync } from 'iguazu';
import { queryModule } from 'iguazu-holocron';

const MyModule = ({ data }) => <p>{`Data: ${data}`}</p>)

function loadDataAsProps({ store }) {
  return {
    data: () => store.dispatch(queryData()),
  };
}

MyModule.loadDataAsProps = loadDataAsProps;
MyModule.loadModuleData = configureIguazuSSR;

export default connectAsync({ loadDataAsProps })(MyModule);

📚 Further Reading

📜 Available Scripts

To test out any changes that you've made locally, run yarn pack then install this within your application.

The scripts below are available to run and use:

yarn babel

This deletes the current JS files within the lib directory and compiles the ECMAScript 6 code within the src file to a version of ECMAScript that can run in current browsers using Babel afterwards it copies them to the lib folder.

yarn build

This runs yarn babel

yarn prepublish

This runs yarn build