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

crorm

v6.0.0

Published

Catch&Release ORM

Downloads

56

Readme

Catch&Release ORM

Catch&Release ORM is a heavily opinionated React/Redux ORM

Why an ORM?

The ORM should remove boilerplate and simplify immutable access.

Example:

Old style:

// HeroCard.jsx

import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';

import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import { actions } from 'heroActions';

import HeroAvatar from 'heroAvatar';
import HeroDetails from 'heroDetails';

export class HeroCard extends React.Component {
  static propTypes = {
    heroId: PropTypes.number.isRequired,
    hero: ImmutablePropTypes.Map.isRequired,
    destroyHero: PropTypes.func.isRequired
  }
  
  render() {
    const { heroId, hero, destroyHero } = this.props;
    
    return (
      <Fragment>
        <button onClick={destroyHero(heroId)}>Destroy Hero</button>
        <HeroAvatar {...{ hero }} />
        <HeroDetails {...{ hero }} />
      </Fragment>
    ); 
  }
} 

const mapStateToProps = (state, props) => ({
  hero: state.data.getIn(['entities', 'hero', props.heroId.toString()], Immutable.Map())
});

function mapDispatchToProps(dispatch) {
  return bindActionCreators({
    destroyHero: actions.destroyHero
  }, dispatch);
}

export default connect(mapsStateToProps, mapDispatchToProps)(HeroCard);

New Style:

// Hero.js
import ORM from 'crorm';
import { actions } from 'heroActions';

export class Hero extends ORM.Base({ id: null }, 'hero') {
  onDestroy(hero, dispatch) {
    dispatch(actions.destroyHero(hero.id));
  }
}
// HeroCard.jsx

import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import ORM from 'crorm';

import Hero from 'hero';

import HeroAvatar from 'heroAvatar';
import HeroDetails from 'heroDetails';

export class HeroCard extends React.Component {
  static propTypes = {
    heroId: PropTypes.number.isRequired,
    hero: PropTypes.shape({
      entity: PropTypes.object
    })
  }
  
  render() {
    const { hero } = this.props;    
    
    return (
      <Fragment>
        <button onClick={hero.destroy()}>Destroy Hero</button>
        <HeroAvatar {...{ hero }} />
        <HeroDetails {...{ hero }} />
      </Fragment>
    ); 
  }
}

const mapStateToProps = (state, props) => ({
  hero: Hero.findById(props.heroId)
});

export default connect(mapStateToProps)(HeroCard);

Expectations

  • Redux data is Immutable utilizing Immutable.Record
  • Data is in the JSONAPI format
  • Data has been parsed using jsonapi-normalizer
  • Actions are all CRUD based
  • Redux Store should have a { data } reducer via combinedReducers.

Setting Up

import { ORM } from 'crorm';

import { store } from 'mystore';

ORM.Config.database = store;

To Add Debug Output: ORM.Config.debug = true;

Create your Class

class Animal extends ORM.Base {};

Class Methods

database() - Get the Redux Store.

dispatch() - Get the Redux Store dispatch function.

recordType() - Get the name of your model in redux, i.e. 'hero'.

order() - Get an Immutable List of ids containing the server ordering for the current entityType.

ordered(props = {}) - Get an Immutable List of ordered instances for the current entityType.

pagination() - Get the pagination for the current entityType.

findById(id) - Get the instance matching the id for the entityType. Returns instance with empty Immutable.Map() when not found.

all() - Get and Immutable Map for all entities of entityType.

where(props = {}) - Get the instances where all props are matching.

create(props = {}) - Create an instance with the passed in props. Call an onCreate method to be overridden for server save and state update.

Instance Methods

Dot Access - Props can be added or edited using '.'.

valid() - Override to provide instance validation, return a boolean.

updateProps(props = {}) - Update the current values and returns a new instance with the passed in props. Calls an onUpdate to be overridden to save on the backend and update the store.

destroy() - Marks the current model as destroyed and returns a "destroyed" instance. Calls an onDestroy to be overridden to save on the backend and update the store.

onCreate(dispatch, createProps) - Override to define what happens on create.

onUpdate(dispatch, updateProps) - Override to define what happens on update.

onDestroy(dispatch) - Override to define what happens on destroy.

Pushing a New Version

  • npm run build && npm publish