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

feat(bind): factory with nested keys #78

Merged
merged 2 commits into from
Aug 16, 2020
Merged

Conversation

josepot
Copy link
Member

@josepot josepot commented Aug 15, 2020

A WIP to explore @voliva suggestion's on this comment of #77

@josepot josepot added the WIP Work in progress label Aug 15, 2020
@josepot josepot requested a review from voliva August 15, 2020 15:14
@josepot josepot force-pushed the feat/bind-factory-nexted-keys branch from d81afee to e86dfd3 Compare August 15, 2020 15:17
@codecov
Copy link

codecov bot commented Aug 15, 2020

Codecov Report

Merging #78 into main will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main       #78   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          293       321   +28     
  Branches        35        39    +4     
=========================================
+ Hits           293       321   +28     
Impacted Files Coverage Δ
packages/core/src/bind/connectFactoryObservable.ts 100.00% <100.00%> (ø)
packages/core/src/bind/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a801f81...4ffa89c. Read the comment docs.

@josepot josepot force-pushed the feat/bind-factory-nexted-keys branch from e86dfd3 to 794f1e5 Compare August 15, 2020 22:41
@josepot josepot removed the WIP Work in progress label Aug 15, 2020
@josepot
Copy link
Member Author

josepot commented Aug 15, 2020

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? 😄

@josepot josepot force-pushed the feat/bind-factory-nexted-keys branch from a6e90d6 to a71c096 Compare August 16, 2020 00:07
Copy link
Collaborator

@voliva voliva left a 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> {
Copy link
Collaborator

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

Copy link
Member Author

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
Copy link
Collaborator

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].

Comment on lines 49 to 52
export function bind<A extends (number | string | boolean | null)[], O>(
export function bind<
A extends (number | string | boolean | null | Object | Symbol | undefined)[],
O
>(
Copy link
Collaborator

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?

@josepot josepot force-pushed the feat/bind-factory-nexted-keys branch from a71c096 to 4ffa89c Compare August 16, 2020 14:08
@josepot josepot merged commit 2d58fba into main Aug 16, 2020
@josepot josepot deleted the feat/bind-factory-nexted-keys branch August 16, 2020 14:25
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