Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Awkward reference to dot-separated strings #6

Closed
VinSpee opened this issue Jan 19, 2022 · 8 comments
Closed

Awkward reference to dot-separated strings #6

VinSpee opened this issue Jan 19, 2022 · 8 comments

Comments

@VinSpee
Copy link

VinSpee commented Jan 19, 2022

const posts = await client.query(queries['post.all']);

In my opinion, this syntax is unnatural in JS/TS. It’s acceptable when the value is just a string, but in this case, it’s a dot-separated string which is the property of an object. It feels quirky and IMO really exposes this as a DSL, a “magic string”.

Since we’re considering an alternative syntax anyway, is there a stance against making procedures referenceable as objects? Example:

const posts = await client.query(queries.post.all);

thanks!

@KATT
Copy link
Member

KATT commented Jan 20, 2022

I'd ideally like this too. However that would require the underlying object to be in this format:

const procedures = {
  queries: {
    post: {
      all: () => {}
    }
}

While this is nice, it might be hard to achieve this recursively and lead to the same sort of complexity costs that we have now. Not sure if it's possible even. Might have a stab at it.

KATT added a commit that referenced this issue Jan 20, 2022
@KATT
Copy link
Member

KATT commented Jan 20, 2022

Had a quick stab at 693b067
Screenshot 2022-01-20 at 00 11 48

Got any ideas?

@KATT
Copy link
Member

KATT commented Jan 20, 2022

I guess it could also be done in that proxy object.... sort of parsing the strings and turning them into a new object based on the dot-notation, that should be possible.

@KATT
Copy link
Member

KATT commented Jan 20, 2022

Can also be solved by not using dot notation, you can use _ as a separator or CamelCase your procedure names.

@VinSpee
Copy link
Author

VinSpee commented Jan 20, 2022 via email

@KATT
Copy link
Member

KATT commented Jan 22, 2022

I do think that the current DX is superior once you get used to it though:

  • VSCode automatically adds that awkward [''] for you
  • You get presented with all the alternatives upfront so you can do fuzzy search for the procedure you wanna access

@KATT
Copy link
Member

KATT commented Feb 1, 2022

The new recommended convention will be to camelCase or snake_case rather than dot notation.

@KATT KATT closed this as completed Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants