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

Accept Plain functions in every combinator #155

Merged
merged 8 commits into from
Jun 27, 2024
Merged

Conversation

gustavoguichard
Copy link
Collaborator

@gustavoguichard gustavoguichard commented Jun 24, 2024

This PR introducing the tagging of composables at both type and runtime levels: fn.kind = 'composable'

This allows us to achieve: Composable<Composable<() => void>> === Composable<() => void>.

And by doing so we are now able to accept plain functions in any combinator, like so:

const add = (a: number, b: number) => a + b

// Before this PR:
const fn = collect({ add: composable(add), toString: map(composable(add), String) })

// With this PR:
const fn = collect({ add, toString: map(add, String) })

There are still 2 todos to my goal:

  • Make the branch resolver function be able to return plain functions instead of only composables or null
  • Make the applySchema work with plain functions and then we can deprecate withSchema because they will be virtually the same

I think this PR as is can be merged and the remaining tasks can come later as new features.

@gustavoguichard gustavoguichard marked this pull request as ready for review June 26, 2024 21:48
@gustavoguichard gustavoguichard force-pushed the tagged-composable branch 2 times, most recently from 1f2a7ce to c83bbb0 Compare June 26, 2024 21:56
@gustavoguichard gustavoguichard changed the title Tag composables at type level and runtime Accept Plain functions in every combinator Jun 26, 2024
@gustavoguichard gustavoguichard added the enhancement New feature or request label Jun 27, 2024
diogob
diogob previously approved these changes Jun 27, 2024
Copy link
Contributor

@diogob diogob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@gustavoguichard gustavoguichard merged commit c942b4a into main Jun 27, 2024
1 check passed
@gustavoguichard gustavoguichard deleted the tagged-composable branch June 27, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants