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

lore-utils

v0.13.0

Published

Functions and files used across multiple Lore packages

Downloads

26

Readme

lore-utils

A catch-all folder for any functions used in multiple places across the Lore ecosystem.

  1. ActionTypes: Factory that generates ActionTypes based on Lore's naming conventions
  2. PayloadStates: Default PayloadStates used by the action blueprints
  3. Hook: Defines the interface implemented by all hooks
  4. payload: A function to convert a Model into a payload for an action
  5. payloadCollection: A function to convert a Collection into a payload for an action

Payload

Converts a model into a payload for an action. Also defines the structure of the data passed around the application.

function payload(model, state, error) {
  return {
    id: model.id,
    cid: model.cid,
    state: state,
    error: error || {},
    data: model.toJSON()
  };
}

PayloadCollection

Converts a collection into a payload for an action. Also defines the structure of the data passed around the application.

function payloadCollection(collection, state, error, query) {
  return {
    state: state,
    error: error || {},
    data: collection.models.map(function( model ) {
      return payload(model, state, error);
    }),
    query: query,
    meta: collection.meta
  };
}

PayloadStates

Stores the PayloadStates used by action and reducer blueprints. Default states are:

module.exports = {
  INITIAL_STATE: 'INITIAL_STATE',

  RESOLVED:  'RESOLVED',
  NOT_FOUND: 'NOT_FOUND',

  CREATING: 'CREATING',
  UPDATING: 'UPDATING',
  DELETING: 'DELETING',
  FETCHING: 'FETCHING',

  ERROR_CREATING: 'ERROR_CREATING',
  ERROR_UPDATING: 'ERROR_UPDATING',
  ERROR_DELETING: 'ERROR_DELETING',
  ERROR_FETCHING: 'ERROR_FETCHING'
};

Needed improvements

Something's weird about this. The true set of PayloadStates (from Lore's perspective) is this file plus whatever custom Payload States the user specifies in src/constants/PayloadStates.js, a file which starts off empty.

This file was created because Lore needs to emit PayloadStates in the action blueprints. But it's obnoxious and opaque that there's no easy way for a user to learn what they are. One idea is created a CLI command like lore payloadStates that lists the full set of payload states for the application. That would at least give the user something to copy/paste when they need to check them. Another option is to copy them into src/constants/PayloadStates as part of the 'lore-generate-new' project generator (the thing responsible for generating the new project structure).

Additionally, PayloadStates are usable in any component, and trying to keep track of the relative path is obnoxious. It doesn't take a very large app before you have require statements in components like:

var PayloadStates = require('../../../../constants/PayloadStates');

We should solve this by either:

  1. Aliasing src/constants in webpack.config.js as constants, so you can require PayloadStates as require('constants/PayloadStates')

  2. Attaching PayloadStates to lore as lore.PayloadStates.XYZ. The downside with that is auto-complete will break, as PayloadStates becomes a dynamic object, but I believe aliasing will also cause that issue.