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

Feature: Dev experience for createCommand #6021

Open
etrepum opened this issue May 4, 2024 · 1 comment
Open

Feature: Dev experience for createCommand #6021

etrepum opened this issue May 4, 2024 · 1 comment
Labels
devx enhancement Improvement over existing feature

Comments

@etrepum
Copy link
Contributor

etrepum commented May 4, 2024

It would be great if we could come up with some ways to enable better introspection and debuggability in prod builds for createCommand. The transform that createCommand does right now is irreversible and the choice of prod vs. dev build infects user code because the type information is thrown away in the constructor.

export function createCommand<T>(type?: string): LexicalCommand<T> {
  return __DEV__ ? {type} : {};
}

I suggest we change the implementation to an unconditional return {type};

export function createCommand<T>(type?: string): LexicalCommand<T> {
  return {type};
}

This leaves the decision of whether to provide a type or not to the caller. Might increase the bundle size by probably about 1kb if we do nothing else?

Compression options

If we want to sacrifice DX in the same way that we do now, but in a way that only affects library code, we can have a transform like transform-error-messages simply remove the argument in prod builds.

If a particularly optimization-focused caller really wants to conditionally throw away the type, they can already do that pretty easily with their own wrapper, a ternary at each call site, or a transform (as above).

Another compression option here would be to have something like transform-error-messages that replaces longer strings with shorter ones, e.g. ':1' and we would expect that any command that has a type starting with ':' should be found in an out-of-bundle-table (that the dev tools would ship with). If we were byte-conscious we could use a more dense encoding than decimals.

A slight modification to the above would be to change the type to type?: string | number which would let us have an out-of-bundle table and serial id transform, to save a few uncompressed bytes for each command (since numbers don't have 2 characters of syntax overhead).

RE #2942
/cc @StyleT @acywatson @thegreatercurve

@etrepum etrepum added the enhancement Improvement over existing feature label May 4, 2024
@StyleT StyleT added the devx label May 4, 2024
@StyleT
Copy link
Contributor

StyleT commented May 4, 2024

Hi!

Thanks for describing it. We can indeed use transform table here for built in commands (and extension would have it) and then let user to decide how to deal with custom commands on their own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devx enhancement Improvement over existing feature
Projects
None yet
Development

No branches or pull requests

2 participants