Powerful Web Application Data Storage and State Management Solution.
New Introducing AppState for global state management
Full Changelog: https://github.com/beforesemicolon/client-web-storage/compare/1.7.0...1.7.1
New
on
and off
store methods to listen(subscribe) to specific store eventsintercept
store method to perform side effects before data is saved to the store on a specific event instead of all events like beforeChange
methodPROCESSING
event to track when the store is performing an actionImprovements
Fixes
Breaking changes
MEMORY_STORE
to MEMORYSTORE
for naming consistencyMEMORYSTORE
DELETED
renamed to REMOVED
size
is no longer a property. It is a async
function. This was because of a bug that was causing it to return inacurate resultsFull Changelog: https://github.com/beforesemicolon/client-web-storage/compare/1.5.0...1.6.0
ArrayOf
and OneOf
for schemasconst exampleSchema = new Schema<Prop>('example', {
id: new SchemaValue(OneOf(String, Number)), // define multiple type options for value
options: new SchemaValue(ArrayOf(String)), // specify what type of array it is
}, false)
beforeChange
return for CREATED
, UPDATED
, and LOADED
events
const unsub = todoStore.beforeChange(async (eventType, data) => {
switch (eventType) {
case ClientStore.EventType.CREATED:
return await todoService.createTodo(data); // <- return the data
case ClientStore.EventType.UPDATED:
return await todoService.updateTodo(data.id, data); // <- return the data
case ClientStore.EventType.LOADED:
return await todoService.getAllByIds(data.map(m => m.id)); // <- return the data
default:
};
return true; // required to flag the store that the action should continue
});
LOADED
was not broadcasted when the list provided was empty.includeDefaultKeys
was set to falseCWS
object on the clientFull Changelog: https://github.com/beforesemicolon/client-web-storage/compare/1.4.5...1.5.0
loadItems
into its own action so it does not keep triggering create
and update
events for every item on the list which can cause infinite loops between the api listener and the data creation;Improvements:
loadItems
no longer leave the store size at its previous state. The size of the store reflects the new items loaded;beforeChange
is now typedFull Changelog: https://github.com/beforesemicolon/client-web-storage/commits/1.4.5
Browser storage interface for IndexedDB, WebSQL, LocalStorage, and in-memory- data with basic Schema and data validation.
// Define schema TS type
import {ClientStore, Schema} from "client-web-storage";
interface ToDo extends Schema.DefaultValue {
name: string;
description: string;
complete: boolean;
}
// create and define schema
const todoShema = new Schema<ToDo>("todo");
todoShema.defineField("name", String, {required: true});
todoShema.defineField("description", String);
todoShema.defineField("complete", Boolean);
// create and use the store
const todoStore = new ClientStore("todos", todoShema);
todoStore.createItem({
name: "Go to Gym" // only name is required
});
/* Creates item in the store
{
id: 3284732894792342, // generated id
name: "Go to Gym",
description: "",
complete: false,
createdDate: "January, 4th 2022",
lastUpdatedDate: "January, 4th 2022",
}
*/
Full Changelog: https://github.com/beforesemicolon/client-web-storage/commits/1.3.0