@vueent/store
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

@vueent/store

This library is a part of VueentT project. It provides Collection, Store, and StoreService classes. Collection incapsulates a loading, creation, updating and deletion of its models, controls a models lifecycle. Store class provides a central storage of collections. Collections do not support relations yet, but models data may be a structured object.

::: warning The library is experimental, API breaking changes may be occured. :::

Installation

npm install --save-dev @vueent/core

Using store service

Define available collections as an argument of generic type of StoreService to support compile time types constrains, e.g.:

store.get(UnknownCollectionClass); // ts: Argument of type 'typeof UnknownCollectionClass' is not assignable to parameter of type...
// file: services/store.ts
import { StoreService } from '@vueent/store';

import { Service, registerService } from '@/vueent';
import { UsersCollection, ArticlesCollection } from '@/collections';
import { EncodedData as EncodedUserData } from '@/models/user';
import { EncodedData as EncodedArticleData } from '@/models/article';

export class ProjectStoreService extends StoreService<UsersCollection | ArticlesCollection> {
  constructor(serverStores: {
    users: {
      mapStore: Map<number, EncodedUserData>;
      getNewPk: () => number;
    };
    articles: {
      mapStore: Map<number, EncodedArticleData>;
      getNewPk: () => number;
    };
  }) {
    super([
      new UsersCollection(serverStores.users.mapStore, serverStores.users.getNewPk),
      new ArticlesCollection(serverStores.articles.mapStore, serverStores.articles.getNewPk)
    ]);
  }
}

registerService(StoreService);

LICENSE

MIT

Package Sidebar

Install

npm i @vueent/store

Weekly Downloads

1

Version

0.6.0

License

MIT

Unpacked Size

131 kB

Total Files

18

Last publish

Collaborators

  • devoter