4 ms·
> Imagine I want to test a function that operates on quite large application state but not all app state is necessary for that function If not all app state is
by hither_shores 4y ago
> Imagine I want to test a function that operates on quite large application state but not all app state is necessary for that function
If not all app state is necessary for that function, it shouldn't require the whole app state in its arguments.
type AppState = { databaseConnection: DatabaseConnection, env : "dev" | "prod", apiToken: string, userId: string, ... } & SomeOtherStuff
const dropTables = (app: Pick<AppState, "databaseConnection"> & {env: "dev"} ) => app.databaseConnection.dropTables()
Conversely, if a function you don't control says it needs the whole app state, believe it.