vuex-orm-get-or-fetch
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Vuex ORM GET-OR-FETCH CircleCI

Allow to get data from the registered model in the vuex-orm store entities or to fetch it by an api call

QuickStart

Installation

npm install @vuex-orm/core vuex-orm-get-or-fetch --save 

Setting up

import Vue from "vue";
import Vuex from "vuex";
import VuexORM from "@vuex-orm/core";
import VuexOrmGetOrFetch from "vuex-orm-get-or-fetch";

Vue.use(Vuex);

const database = new VuexORM.Database();
database.register(YourModel);

VuexORM.use(VuexOrmGetOrFetch, { database });

Usage

In your vuex-orm model definition, you can define two static property (retrieveAction, listAction)

export class Site extends Model {
  static retrieveAction = "namespaced_module/youActionToDispatch";
  static listAction = "namespaced_module/youActionToDispatch";

  static fields() {
    return {
      uuid: this.uid(""),
    };
  }
}

export class Building extends Model {
  static retrieveAction = "namespaced_module/youActionToDispatch";
  static listAction = "namespaced_module/youActionToDispatch";

  static fields() {
    return {
      uuid: this.uid(""),
      site: this.string(""), // foreign key
      siteData: this.belongsTo(Site, "site"),
    };
  }
}
  • static retriveAction

Allow to perform :

.getFromStoreOrFetchOne(uuid: string) as a Model query
const building = await Building.query().getFromStoreOrFetchOne(buildingUuid)
.getFromStoreOrFetchBelongsTo(belongsToField: string) on a Model instance
const site = await building.getFromStoreOrFetchBelongsTo("siteData");
  • static listAction

comming soon...

Readme

Keywords

Package Sidebar

Install

npm i vuex-orm-get-or-fetch

Weekly Downloads

46

Version

1.0.2

License

MIT

Unpacked Size

23.4 kB

Total Files

5

Last publish

Collaborators

  • mickaelspennato