Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
phortx committed Jun 7, 2018
1 parent a1edbd0 commit f76a62f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Logger from './logger';
import Model from './model';
import ORMModel from "@vuex-orm/core/lib/model/Model";
import ORMModel from '@vuex-orm/core/lib/model/Model';
import { Components, Options } from '@vuex-orm/core/lib/plugins/use';
import { downcaseFirstLetter } from './utils';
const inflection = require('inflection');
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ORMModel from "@vuex-orm/core/lib/model/Model";
import ORMModel from '@vuex-orm/core/lib/model/Model';

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

Expand Down Expand Up @@ -36,6 +36,6 @@ export interface Field {
}

export class PatchedModel extends ORMModel {
static async fetch(filter: any, bypassCache = false): Promise<any> { return; };
static async mutate(params: any): Promise<any> { return; };
static async fetch (filter: any, bypassCache = false): Promise<any> { return undefined; }
static async mutate (params: any): Promise<any> { return undefined; }
}
4 changes: 2 additions & 2 deletions src/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ORMModel from "@vuex-orm/core/lib/model/Model";
import { Field, } from './interfaces';
import ORMModel from '@vuex-orm/core/lib/model/Model';
import { Field } from './interfaces';
import Context from './context';
const inflection = require('inflection');

Expand Down
26 changes: 8 additions & 18 deletions src/vuex-orm-apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Model from './model';
import { ApolloClient, FetchPolicy } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import {Data, ActionParams, Arguments, DispatchFunction, PatchedModel} from './interfaces';
import { Data, ActionParams, Arguments, DispatchFunction, PatchedModel } from './interfaces';
import QueryBuilder from './queryBuilder';
import { upcaseFirstLetter } from './utils';
import Context from './context';
Expand Down Expand Up @@ -74,53 +74,43 @@ export default class VuexORMApollo {
this.context.components.subActions.destroy = this.destroy.bind(this);
this.context.components.subActions.mutate = this.customMutation.bind(this);


// Register static model convenience methods
(this.context.components.Model as (typeof PatchedModel)).fetch = async function(filter: any, bypassCache = false) {
(this.context.components.Model as (typeof PatchedModel)).fetch = async function (filter: any, bypassCache = false) {
let filterObj = filter;
if (typeof filterObj !== 'object') filterObj = { id: filter };
return this.dispatch('fetch', { filter: filterObj, bypassCache });
};

(this.context.components.Model as (typeof PatchedModel)).mutate = async function(params: any) {
(this.context.components.Model as (typeof PatchedModel)).mutate = async function (params: any) {
return this.dispatch('mutate', params);
};


// Register model convenience methods
this.context.components.Model.prototype.$mutate = async function(params: any) {
this.context.components.Model.prototype.$mutate = async function (params: any) {
if (!params['id']) params['id'] = this.id;
return this.$dispatch('mutate', params);
};

this.context.components.Model.prototype.$persist = async function(args: any) {
this.context.components.Model.prototype.$persist = async function (args: any) {
return this.$dispatch('persist', { id: this.id, args });
};

this.context.components.Model.prototype.$push = async function(args: any) {
this.context.components.Model.prototype.$push = async function (args: any) {
return this.$dispatch('push', { data: this, args });
};

this.context.components.Model.prototype.$destroy = async function() {
this.context.components.Model.prototype.$destroy = async function () {
return this.$dispatch('destroy', { id: this.id });
};

this.context.components.Model.prototype.$deleteAndDestroy = async function() {
this.context.components.Model.prototype.$deleteAndDestroy = async function () {
await this.$delete();
return this.$destroy();
};

// this.components.subActions.destroyAll = this.destroyAll.bind(this);
}


/**
* Helper to dispatch actions on the store
*/
public dispatch(params: ActionParams) {

}

/**
* Will be called, when dispatch('entities/something/fetch') is called.
*
Expand Down

0 comments on commit f76a62f

Please sign in to comment.