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

grab-a-plate-frontend

v1.0.0

Published

## Golden rule: Think before you type

Downloads

2

Readme

Frontend README

Golden rule: Think before you type

Principles

Single source ot truth is redux. For every side effect we use redux-saga. We prefer hooks over HoC Data fetching and changing on server is done by (@inventi/keep)[https://www.npmjs.com/package/@inventi/keep] (useFetch, useMutate, etc.) - see examples. For styling we use styled-component and (xstyled)[https://xstyled.dev/]. We never use units in padding, margins, etc - that's what xstyled does. See theme in src/App directory. For user permissions we have set up ACL. See permissions in src/App directory.

Creating components

Do NOT create component files youself or by copying older ones. Use scaffolding tool yarn generate in this frontend directory for generating:

  • components
  • pages
  • redux saga modules

Project structure

Explore structure if this project to see all these rules in action.

Components

Divided into groups by its size. All components should contain storybook stories for better development and example usage.

  • Elements

    Basic brick and simplest pieces of puzzle in your application. Must NOT use any other element or block. Never use Redux on an kind of state inside it. Intended to be used by other components.

  • Blocks

    Middle-complex building block in your application. Must NOT use any other block. Never use Redux on an kind of state inside it. If you need it stateful, separate it into Container under Page. Intended to be used by other components.

  • Pages

    The biggest type of component. It can NEVER use other pages inside. Expected to collocate containers and components that are only related to specific page.

Store

We use redux. Every logical entity separate into its folder. See for example (cat module)[/src/store/cat].

index.ts is everytime a (duck)[/src/store/cat]. Duck is selector, action type, action create and reducer - all in one.

sagas.ts is only for sagas - sideeffects. Sideeffect is for example data fetching, saving to localStorage, and so on.

Before commit

Check your code style

  • all components in src/components should have storybook
  • Check if storybook works.
  • yarn test => all tests must be passing
  • yarn lint:js =>lint

Challenge implementation of your code if it is (and see further reading below):

  • simple
  • has single responsibility
  • is encapsulated
  • reusable
  • composable

Further reading

  • https://dmitripavlutin.com/7-architectural-attributes-of-a-reliable-react-component/

Cookbook

TS Typeguards

// We take advantage of TS semantic sugar 'value is Date' which indicates that
// if the function returns 'true' => value is indeed an instance of Date... and NOTHING ELSE !
const isDate = (value: Date | any): value is Date => {
  // Do any logic to check whether 'value' is of expected type
  return value instanceof Date
}

function main() {
  // START READING HERE <<
  // Imagine function getDate() returns value representation of some Date,
  // HOWEVER it might return someting else.. you don't know.
  const date: Date | any = getDate()
  
  // When we need to call function Date.toISOString() on it..
  // Calling it on variable which might be undefined or null will result in error.
  
  console.log(date.toISOString()) // Might resolve in following errors
  // TypeError: Cannot read property 'toISOString' of undefined
  // TypeError: Cannot read property 'toISOString' of null
  // TypeError: date.toISOString is not a function
  
  // That's why we need to check whether 'date' is instance of Date
  if (isDate(date)) {
    // We can safely call .toISOString() here..
    console.log(date.toISOString())
  }
}