MiniCrudState extends MiniState to provide specialized support for CRUD (Create, Read, Update, Delete) operations on collections of items. It handles client-side updates to the data array when items are added, updated, or deleted, making it perfect for building data management interfaces.
Key Feature: MiniCrudState automatically maintains the client-side array of items when CRUD operations are performed. This means the UI will update immediately after add, update, or delete operations, without waiting for a subsequent reload of the data.
Creates a new MiniCrudState instance for a collection of items that can be filtered.
Configures the add operation for the CRUD state. When an item is successfully added, it will automatically be appended to the items array in the state.
Configures the update operation for the CRUD state. When an item is successfully updated, the corresponding item in the array will be replaced with the updated version.
Configures the delete operation for the CRUD state. When an item is successfully deleted, it will automatically be removed from the items array in the state.
Sets the function used to determine if two items are equal. This is used when finding items to update or delete in the collection.
Triggers the main operation to load the collection based on the provided filter.
Triggers the add operation with the provided item. When successful, the item will be added to the collection in the state.
Triggers the update operation with the provided item. When successful, the item will be updated in the collection in the state.
Triggers the delete operation with the provided item. When successful, the item will be removed from the collection in the state.
When you call trigger(filter)
, MiniCrudState loads the entire collection based on the provided filter and replaces the current data array.
When you call triggerAdd(item)
, MiniCrudState:
When you call triggerUpdate(item)
, MiniCrudState:
equals
function to find the matching itemWhen you call triggerDelete(item)
, MiniCrudState:
equals
function to find the item to removeThe following example demonstrates a complete user management component using MiniCrudState: