0.6.0 • Published 4 months ago

@vueent/store v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@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