eldoy / waveorb

Javascript web app development framework
https://waveorb.com
MIT License
5 stars 0 forks source link

Models, helpers and data? #78

Open eldoy opened 1 year ago

eldoy commented 1 year ago

Add a directories for models and data in app?

Config is over-used for data, for instance I have this use case:

list-fields.js
company-field.js
api-company-fields.js

If we put this in app/data/fields and access like this it would be nicer:

$.app.data.fields.list
$.app.data.fields.companyField
$.app.data.fields.apiCompanyFields

We also have use cases for shared code between actions which is not suitable for flows, like matchers, finders, etc...

$.app.models.company.performSearch($)
$.app.models.company.matchers.listMatchers

// General across all actions
$.app.models.all.someFunction()

Sometimes we also need helper functions in lib or helpers:

$.app.lib.calculateSomething()
$.app.helpers.calculateSomething()

Could we generalize and just preload everything in the app directory? This may lead to slow startup though, so some kind of lazy-load through a proxy would be nice.

eldoy commented 1 year ago

Example model function in app/models/company:

module.exports = function(app) {
  const { db } = app.objects

  function find($) {
    const { query } = $.params
    return db('company').find(query)
  }

  return { find }
}

Call with:

const result = await $.app.models.company.find($)

Need to expand model into app.models though, like we just reverted with plugins.... Should that be new de-facto?