Skip to content

feat(core): add keys to tokens #8

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

Closed
wants to merge 1 commit into from
Closed

Conversation

raveclassic
Copy link
Owner

@raveclassic raveclassic commented Sep 19, 2022

This PR adds a key: Key property to the result of token call - this makes it much easier to work with tokens by eliminating the need of exporting separate key constants:

// before
const FOO_KEY = 'foo'
const foo = token(FOO_KEY)<string>()
const bar = injectable(foo, foo => 'result')
const result = bar({[FOO_KEY]: 'foo'})

// after
const foo = token('foo')<string>()
const bar = injectable(foo, foo => 'result')
const result = bar({[foo.key]: 'foo'})

BREAKING CHANGE: fp-ts package is removed as useless

cc @devfive @Fyzu @mankdev

Notes:

  • it seems @injectable-ts/fp-ts is absolutely useless as we can't force constraints on the E argument in interface URItoKind2<E, A> so that E is of shape UnknownInjectableTree
  • I had to change how types are encoded on Injectable interface and how they are inferred using InjectableValue/InjectableDependencies - we relied on type argument position before (first is for dependencies, second is for value) but this breaks if we have a TokenInjectable with 3 type arguments; so now we store the arguments as virtual fields (similar to zod schemas)
  • it don't really like all this new mess with type casts but it won't work otherwise (see above ☝️ )

@raveclassic raveclassic force-pushed the tokens_with_keys branch 2 times, most recently from bd86f6b to ece7733 Compare September 19, 2022 14:19
@raveclassic raveclassic marked this pull request as draft September 19, 2022 14:31
BREAKING CHANGE: fp-ts package is removed as useless
@raveclassic raveclassic marked this pull request as ready for review September 19, 2022 16:42
@Fyzu
Copy link

Fyzu commented Oct 14, 2022

I like it! Mb we can provide better typings for DepencyProvider?

@raveclassic
Copy link
Owner Author

Closing as fixed by #10

@raveclassic raveclassic closed this Jan 2, 2023
@raveclassic raveclassic deleted the tokens_with_keys branch January 2, 2023 12:17
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 this pull request may close these issues.

2 participants