Client Web Storage Versions Save

Powerful Web Application Data Storage and State Management Solution.

1.7.1

1 year ago

New Introducing AppState for global state management

Full Changelog: https://github.com/beforesemicolon/client-web-storage/compare/1.7.0...1.7.1

1.6.0

1 year ago

New

  • introduces schema object literal for a more straightforward way to define the schema
  • introduces on and off store methods to listen(subscribe) to specific store events
  • introduces intercept store method to perform side effects before data is saved to the store on a specific event instead of all events like beforeChange method
  • PROCESSING event to track when the store is performing an action
  • the ability to override default keys used by the store as items identifiers and created and updated time

Improvements

  • 100% test coverage
  • Underneath code organization improved
  • better error messages and capture mechanism
  • documentation addresses more details and contains better examples
  • better action interception data handling which allows for more things in the interception handler without compromising the data

Fixes

  • In memory store is no longer a single global store for all items in the app. This issue would cause different stores to save data in the same place instead of being a separate thing

Breaking changes

  • changes MEMORY_STORE to MEMORYSTORE for naming consistency
  • default store type is now in-memory => MEMORYSTORE
  • Event 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 results

What's Changed

New Contributors

Full Changelog: https://github.com/beforesemicolon/client-web-storage/compare/1.5.0...1.6.0

1.5.0

1 year ago

New

  • custom types ArrayOf and OneOf for schemas
const 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)
  • Allow to override the data via 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
});

Fixes

  • LOADED was not broadcasted when the list provided was empty.
  • Schema was removing explicitly defined values which looked like default values when includeDefaultKeys was set to false
  • All classes where being set directly in window. Now they are available under CWS object on the client

What's Changed

Full Changelog: https://github.com/beforesemicolon/client-web-storage/compare/1.4.5...1.5.0

1.4.5

1 year ago
  • Convert 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:

  • Calling loadItems no longer leave the store size at its previous state. The size of the store reflects the new items loaded;
  • beforeChange is now typed
  • Loaded items will now validate all items first before putting them into the store;

What's Changed

New Contributors

Full Changelog: https://github.com/beforesemicolon/client-web-storage/commits/1.4.5

1.3.0

1 year ago

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",
}
*/

What's Changed

Full Changelog: https://github.com/beforesemicolon/client-web-storage/commits/1.3.0