question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use BaseModel as default - simplify makeServicePlugin call

See original GitHub issue

just trying to migrate to 2.0. Need some clarification

in the backend a model and service is created like so

// Initializes the `circuits` service on path `/circuits`
const createService = require('feathers-nedb')
const createModel = require('../../helpers/nedb.model')
const hooks = require('./config.hooks')

module.exports = function () {
  const app = this
  const Model = createModel(app, 'config')
  const paginate = app.get('paginate')

  const options = {
    name: 'config',
    Model,
    events: [],  // custom events
    paginate
  }

  // Initialize our service with any options it requires
  app.use('/config', createService(options))

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('config')

  service.hooks(hooks)
}

I am assuming that is how more or less f-v in V1.7 did it as one only had to pass the service name to the plug-in generator.

In 2.0 one now has to make and pass a BaseModel extended class in which static model name is added

Can the mew makeServicePlugin function take care of all this if it sees a string passed (the service name) and not an object (with model and service)

Seems like that function should/could have access to the feathers object from the feathersVuex call and should be able to create the service as well as the baseModel class instance with the model name if that is what is required. This IMO should be as simple as before if one doesn’t need changes to the BaseModel

const SERVICES = ['config', 'network', 'hardware', 'circuits', 'switches']
plugins: SERVICES.map(name => service(name))

As it is I have to do this hard coding of an extended Class 6 times for my 6 services. Seems a 'createModel` function should be added equivalent to that in feathers itself. Then internally to makeServicePlugin it could be called.

Ok…so I probably should do a PR right 😃. Unfortunately I don’t code in typescript (mainly cause of the transpiler step) but I do write in latest ES6-7/ESM if that is any help.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dkeblercommented, Sep 19, 2019

@marshallswain
This seems to work from https://stackoverflow.com/questions/33605775/es6-dynamic-class-names

const nameIt = (name, cls) => ({ [name]: class extends cls {} })[name]

function createModelClass (name) {
  class Model extends BaseModel {
    constructor (data, options) {
      super(data, options)
      this.modelName = name + 'i'
    }
  static modelName = name
  }
  return nameIt(name, Model)
}
let Test = createModelClass('Test')
console.log('class static modelName', Test.modelName)
console.log('instance modelName', new Test().modelName)
class static modelName Test 
instance modelName iTest

I’ll try it in app now

0reactions
dkeblercommented, Jan 27, 2020

I see many releases since october. Has #276 been resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't find a working example application #252
Use BaseModel as default - simplify makeServicePlugin call #271 ... @knowsarzehmeh, currently, Nuxt cli uses Feathers 3.3.1 during creation ...
Read more >
2.0 Breaking Changes | FeathersVuex
(b) The service method has been renamed to makeServicePlugin . ... import feathersVuex from 'feathers-vuex' const { BaseModel, // (2a) makeServicePlugin, ...
Read more >
Feathers Integration - Alinex GUI
This implements VueX using a feathers based server. It is ready configured to work with the API Server using websockets. Authentication¶. This is...
Read more >
Python [Pydantic] - default values based other object in the ...
Not enough reputation to comment, so I'll just expand on @NobbyNobbs answer here^^. For your last example using pydantic.validator , you can ...
Read more >
feathers-vuex: Versions
We now have a cleaner API for customizing a service's default Vuex store. ... feathers-client.js' class Todo { /* truncated */ } makeServicePlugin({...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found