-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat(bind): factory with nested keys #78
Conversation
d81afee
to
e86dfd3
Compare
Codecov Report
@@ Coverage Diff @@
## main #78 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 293 321 +28
Branches 35 39 +4
=========================================
+ Hits 293 321 +28
Continue to review full report at Codecov.
|
e86dfd3
to
794f1e5
Compare
After the offline conversation that we've had, I had an idea to support optional args (and undefined values). I've put that change in a separate commit so that it's easier to appreciate what the trick is about. So simple, and yet so powerful! I'm just always prepending the number of arguments as the first key of the nested structure... It does the trick, right? 😄 |
a6e90d6
to
a71c096
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks so good 👍
@@ -6,6 +6,52 @@ import { useObservable } from "../internal/useObservable" | |||
import { SUSPENSE } from "../SUSPENSE" | |||
import { takeUntilComplete } from "../internal/take-until-complete" | |||
|
|||
class NestedMap<K extends [], V extends Object> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this in a separate file... I think it's a bit noisy here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to move it below (in the same file). The reason being that NestedMap
is not generic enough to be consumed from anywhere else, it's very tightly coupled to this functionality. So, I decided to to move it below.
for (let i = input.length - 1; input[i] === undefined && i > -1; i--) { | ||
input.splice(-1) | ||
} | ||
const keys = ([input.length, ...input] as any) as A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reminded me of something exciting: The TS release for this month (4.0) will include variadic tuple types - Which will allow us to represent this type as [number, ...A]
.
packages/core/src/bind/index.ts
Outdated
export function bind<A extends (number | string | boolean | null)[], O>( | ||
export function bind< | ||
A extends (number | string | boolean | null | Object | Symbol | undefined)[], | ||
O | ||
>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to specific what types it supports? Could it be unknown[]
or any[]
instead?
a71c096
to
4ffa89c
Compare
A WIP to explore @voliva suggestion's on this comment of #77