Skip to content

fedoranimus/store.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Store.ts

Storage abstraction for Typescript projects. I have no idea how I want this to work yet!

Basic Usage

Everything you need to go to get up and running quickly.

Store.ts is modeled after other data storage systems, exposing the following API. By default, collections are stored in memory.

// Imagine we have the following basic data collection of users
let users = [new User({ "key": 0, "name": "Tom"}), new User({ "key": 1, "name": "Dick"})];

// Create a new Store, seed it with our existing users
// By default, a store looks for the property "key" to use as its primary key
// You can set a different property to be the key by using 'keyProperty'
let store = new Store<User>({ data: users });

// Add a new user
let key = store.put({ "key": 2 "name": "Harry" });

// Get an existing user
let harry = store.get(key);

// Update "Tom" to be "Steve"
let key = store.put({ "key": 0, "name": "Steve" });

// Loop over the entire collection
store.forEach((user) => ({
    console.log(user);
});

// Get the entire collection as an array
store.fetch();

// Remove an existing user
store.delete();

// Clear the collection
store.clear();

Installation

using npm:

// Import the Store module
import Store from 'store-ts';

// Create a new instance of Store
let store = new Store();
store.put({ "name": "Harry" });

Roadmap

  • Plugin System
  • Storage Adapter System
  • Test Cases
  • API Documentation

Plugins

Track

Returned objects give information about their location in the collection

Query

Client-side query functions

store.fetch().where(x => x.name == "Tom");

Async

Each method returns a Promise and are referred to by {name}Async to match the Microsoft nomenclature.

Events

Emit events on add, update, delete

Storage adapters

Memory

IndexedDB

LocalStorage

Contributing

Releases

No releases published

Packages

No packages published