Skip to content

Instantly share code, notes, and snippets.

@davecarter
Last active October 24, 2023 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davecarter/9cf9e84e9c85176e56bcf193bc3186d9 to your computer and use it in GitHub Desktop.
Save davecarter/9cf9e84e9c85176e56bcf193bc3186d9 to your computer and use it in GitHub Desktop.
Domain entry point
import * as blockchainUseCases from "./blockchain/useCases"
import * as dexUseCases from "./dex/useCases"
import * as statsUseCases from "./stats/useCases"
import * as userUseCases from "./user/useCases"
const useCases = {
...blockchainUseCases,
...dexUseCases,
...statsUseCases,
...userUseCases,
}
export class DomainApp {
static create({ config }) {
if (!config) throw new Error("Missing domain config")
return new DomainApp({ config })
}
constructor({ config }) {
this._config = config
Object.entries(useCases).forEach(([key, value]) => {
const useCaseName = key.charAt(0).toLowerCase() + key.slice(1)
this[useCaseName] = this._getter(value)
})
}
_getter(useCase) {
const config = this._config
return {
async execute() {
const instance = await useCase.create({ config })
return instance.execute(...arguments)
},
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment