Skip to content

Commit 1f556d5

Browse files
committed
Use the model and convenience methods from vuex-orm
1 parent 7723a64 commit 1f556d5

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

src/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Logger from './logger';
22
import Model from './model';
3-
import { ORMModel } from './interfaces';
3+
import ORMModel from "@vuex-orm/core/lib/model/Model";
44
import { Components, Options } from '@vuex-orm/core/lib/plugins/use';
55
import { downcaseFirstLetter } from './utils';
66
const inflection = require('inflection');

src/interfaces.ts

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Model from './model';
1+
import ORMModel from "@vuex-orm/core/lib/model/Model";
22

33
export type DispatchFunction = (action: string, data: Data) => Promise<any>;
44

@@ -28,21 +28,6 @@ export interface Arguments extends Object {
2828
[index: string]: any;
2929
}
3030

31-
export interface ORMModel {
32-
name: string;
33-
entity: string;
34-
eagerLoad: undefined | Array<string>;
35-
skipFields: undefined | Array<string>;
36-
37-
fields (): any;
38-
dispatch (name: string, ...params: Array<any>): any;
39-
getters (name: string, ...params: Array<any>): any;
40-
attr (defaultValue: any): Field;
41-
boolean (defaultValue: boolean): Field;
42-
number (defaultValue: number): Field;
43-
string (defaultValue: string): Field;
44-
}
45-
4631
export interface Field {
4732
related?: ORMModel;
4833
parent?: ORMModel;

src/model.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Field, ORMModel } from './interfaces';
1+
import ORMModel from "@vuex-orm/core/lib/model/Model";
2+
import { Field, } from './interfaces';
23
import Context from './context';
34
const inflection = require('inflection');
45

@@ -118,7 +119,7 @@ export default class Model {
118119
}
119120

120121
public getRecordWithId (id: number) {
121-
return this.baseModel.getters('query')().withAllRecursive().where('id', id).first();
122+
return this.baseModel.query().withAllRecursive().where('id', id).first();
122123
}
123124

124125
public fieldIsNumber (field: Field | undefined): boolean {

src/vuex-orm-apollo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export default class VuexORMApollo {
129129
// in this case this.mutate has inserted a new record instead of updating the existing one.
130130
// We can see that because $isPersisted is still false then.
131131
this.context.logger.log('Dropping deprecated record with ID', oldRecord.id);
132-
await model.baseModel.dispatch('delete', { where: oldRecord.id });
132+
await model.baseModel.delete({ where: oldRecord.id });
133133
}
134134

135135
return newRecord;
@@ -232,7 +232,7 @@ export default class VuexORMApollo {
232232
} else {
233233
this.context.logger.log("Couldn't find the record of type", model.pluralName, 'in', insertedData,
234234
'. Fallback to find()');
235-
return model.baseModel.getters('query')().last();
235+
return model.baseModel.query().last();
236236
}
237237
}
238238

0 commit comments

Comments
 (0)