No release in over 3 years
Low commit activity in last 3 years
A half-baked solution to standardizing CRUD operations with a frontend client.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 5.0, < 7.0

Runtime

>= 5.0, < 7.0
 Project Readme

crud-muffins

A half-baked solution to UI CRUD operations.

Motivation

Because I got super tired of writing the basic state management of CRUD operations in my webapps, including:

  1. Loading the collection (Reading)
  2. Creating a new item
  3. Updating an item
  4. Deleting an item
  5. ...and all the UI state associated with it (e.g. isEditing, isSaving, etc.)

Setup

$ yarn add crud-muffins

This package is not transpiled and written with modern JS syntax. You can add this package to the list of node_modules you transpile manually.

Why? My current understanding is that it makes code bundles smaller overall when there's only one transpilation, as opposed to each module transpiling in its own context. Happy to be convinced otherwise!

Usage

The API will likely change quite a lot over the next several iterations. It's designed to work with any UI library, e.g. React, you just need to pass in the controls for reading/setting state.

Here's an example usage in React:

// some special function to process/extract data from the server payload
const unbox = response => ({
  data: compose(map(prop('data')), prop('data'), prop('data'))(response),
  pagination: response.data.pagination,
})

const {
  create, load, update, destroy, items,
  ui: { isSaving, isEditing, startEditing, stopEditing, isSavingNew },
} = useCrudMuffins(axios, '/todos', ...useState([]), ...useState({}), { loadPostProcessor: unbox })

/**
 * From there you can do things like:
 * 
 *   - await load(params)
 *   - await update(id, params)
 *   - await create(params)
 *   - isSaving(id)
 *   - isEditing(id)
 *   - startEditing(id)
 *   - stopEditing(id)
 * 
 * etc...
 */

Working demo example to come.

Credits

Image credit: @zspencer

Code collaborator: @zspencer