vue-mc icon indicating copy to clipboard operation
vue-mc copied to clipboard

Decoupling vue-mc from RESTful APIs

Open bshepherdson opened this issue 3 years ago • 1 comments

I really like the patterns vue-mc brings! Thanks for building it and documenting it clearly.

I saw a question about GraphQL, and this might be similar. I'm working with a gRPC backend, not a JSON REST endpoint. Some of the RPCs it defines are very straightforward CRUD requests and could easily be adapted to the fetch/save/delete patterns of vue-mc.

However, the assumption that we're targeting a JSON REST API is deeply shot through the design and API of vue-mc.

Has there been any work on this front before? It seems sane in principle to use a Strategy pattern, so most of vue-mc is written against a generic request/response interface and then have REST, gRPC and other (including user-supplied) implementations.

With Vue 3 (and its new ref() reactivity system) in RC, is an overhaul of vue-mc planned or in progress? That might be a good time to make the changes I'm imaging.

bshepherdson avatar Aug 20 '20 16:08 bshepherdson

@shepheb,

I've done it via extending the model

import { fetch, save, remove } from './adapters/PouchDB'

...

export default class BaseModel extends Model {

...

 /**
   * Overide parent's @fetch method to retrive data from the database 
   *fetch
   * @param {*} document
   * @memberof BaseModel
   */
  fetch(document) {
    // call fetch from PouchDB
    fetch.call(this, document)
  }

...


  /**
   *Overide parent's @onFetchSuccess handler to retrive data from the database
   *onFetchSuccess
   * @param {*} snapshot
   * @returns document
   * @memberof BaseModel
   */
  onFetchSuccess(snapshot) {
    return snapshot;
  }

Skuudoer avatar Aug 24 '20 13:08 Skuudoer