Use BaseModel as default - simplify makeServicePlugin call
See original GitHub issuejust 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:
- Created 4 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
@marshallswain
This seems to work from https://stackoverflow.com/questions/33605775/es6-dynamic-class-names
I’ll try it in app now
I see many releases since october. Has #276 been resolved?