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

purefacts-widgets

v1.0.0

Published

This project is a library containing React widgets that can be re-used in PureReporting NextGen applications.

Downloads

7

Readme

Overview

This project is a library containing React widgets that can be re-used in PureReporting NextGen applications.

Two important things to take notice of:

  • To publish this project as an NPM package into a dummy repository, this project uses verdaccio. See below on how to use it (there are links and resources available to you to become familiar with this tool). And yes, you can use any non-public repository running locally or in PureFacts, but we recommend this Verdaccio & cover only that one in the tutorials below.

  • To test the components without needing a host app, we use React Storybook components. Again there are links and resources provided below.

A note about creating components

Please create components using command line - for example:

npx generate-react-cli component AssetGraph
npx generate-react-cli component --path=src/components/test HelloWorld

We use this plugin to make sure the syntax of components are the same. This keeps this project clean and consistent.

If you are familiar with Angular, you know that Angular command line client helps Angular developers maintain their code and keep it clean; however, there are just too many flavours and tools to do the equivalent job in React world. Here we are using this tool: https://github.com/arminbro/generate-react-cli

Remark: Using this plugin allows us to add storybook templates by default. That and more are all configured inside generate-react-cli.json (something you should know by now if you had studied their doc in above link).

Installing Verdaccio

Verdaccio is a dummy local repository that we can use to test. The idea is to publish this package into your local repo, and to install it in your host app.

For example, after publishing this package into your local verdaccio instance, you can install it into our PureReporting Nextgen UI app.

Verdaccio is well documented and your best friend is the YouTUBE video found in their readme. Please see this link: https://verdaccio.org/ and click on docs on top menu.

Using React Storybook To Test

React Storybook allows developers of plugins and components to test their plugins right there.

As you know, if you are developing a library such as this one, your time would be wasted if you were to compile the plugin, publish the npm, update the plugin in host, and refresh just to see your change.

That's why Storybook is useful.

I think this video does a great job explaining what Storybook is all about. Please review this tutorial fully. https://www.youtube.com/watch?v=FUKpWgRyPlU&t=932s

Storybook (AKA @storybook/react) is currently broken on 6.4

The version has been temporarily set to 6.3 until https://github.com/storybookjs/storybook/issues/16880 is fixed

Using Snapshot testing

Snapshot testing is used to confirm that the output of a component for a given props stays the same. To create a new snapshot test (Or to update the old one, when you know that the new snapshot state is correct).

npm run update-snapshots

There are 2 major ways to do snapshot testing. enzyme and react-test-renderer.

The different is that react-test-renderer only tests the HTML outputted by a given component, but enzyme allows you to compare more detailed things.

A good example of the difference, when testing is testing anything with recharts. The output of recharts will not show up with react-test-renderer, so we cannot test what we made.

With enzyme, we can see the props which have been given to recharts, so we can at least be sure the props we passed to recharts did not change.

How to use some of the more advanced hooks

useMemo and merging default parameters

A perfect useCase for useMemo is this

const Component = props => {
  const propsMergedWithDefault = useMemo(() => {
      return merge(props, defaultProps);
    }, [props]
  )
  // ...
}

Which can replace the unclear and incorrect following pattern

const Component => props => {
    const [propsMergedWithDefault, setPropsMergedWithDefault] = useState(defaultProps);
    // ...
    useEffect(() => {
      setPropsMergedWithDefault(merge(props, defaultProps)
    }, [props])
}

Jest and snapshot tests

npm run test-jst will execute all tests. Many of these are snapshot tests which will check that your changes didn't change a component in an indesired way. If you changed a component on purpose, then use npm run update-snapshots and commit the changed files.