Last active
October 24, 2023 07:56
-
-
Save davecarter/9cf9e84e9c85176e56bcf193bc3186d9 to your computer and use it in GitHub Desktop.
Domain entry point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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