Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using a group of providers at once #16

Open
jasonkuhrt opened this issue Oct 2, 2021 · 3 comments
Open

Allow using a group of providers at once #16

jasonkuhrt opened this issue Oct 2, 2021 · 3 comments

Comments

@jasonkuhrt
Copy link
Member

Perceived Problem

const ctx = kont()
  .useBeforeAll(a())
  .useBeforeEach(b())
  .useBeforeEach(c())
  .done()

What if consumer/producer wants to be able to have a,b,c providers packages up
into one group of providers?

Ideas / Proposed Solution(s)

const ctx = kont()
  .useBeforeAll(a(), b(), c())
  .done()
const group = [a(), b(), c()]

const ctx = kont()
  .useBeforeAll(...group)
  .done()
const ctx = kont()
  .useBeforeAll([a(), b(), c()])
  .done()
const group = [a(), b(), c()]

const ctx = kont()
  .useBeforeAll(group)
  .done()
@jasonkuhrt
Copy link
Member Author

jasonkuhrt commented Oct 18, 2021

const group = [a(), b(), c()]

const ctx = konn()
  .useBeforeAll(group)
  .done()

A problem with this is when downstream depends on upstream, then those types are lost in the group definition.

To fix we need a function helper.

const abc = join(a(), b(), c())

const ctx = konn()
  .useBeforeAll(abc)
  .done()

@jasonkuhrt
Copy link
Member Author

What if consumer wants to reuse repetitive parts of konn chain?

const ctx = konn()
  .useBeforeAll(a())
  .useBeforeAll(b())
  .useBeforeEach(c())
  .done()

Ideas

const abc = konn()
  .useBeforeAll(a())
  .useBeforeAll(b())
  .useBeforeEach(c())

// maybe another file, maybe multiple
const ctx = konn().use(abc).done()

.use would take a callback to get the callback to be contravariant to the host ctx type:

const ctx = konn().use(thing).use({ _use: (ctx) => /* ... */ }).done()

This would require the konn chain to have a _use helper that would provide the needed static type state.

Alternative using a new API group:

const abc = group()
  .useBeforeAll(a())
  .useBeforeAll(b())
  .useBeforeEach(c())
  .done()

// maybe another file, maybe multiple
const ctx = konn().use(abc).done()

@jasonkuhrt
Copy link
Member Author

Maybe different function name, providersGroup instead of join:

const abc = providersGroup(a(), b(), c())

const ctx = konn()
  .useBeforeAll(abc)
  .done()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant