Skip to content

fix: add BuildOptions to build method in IClientConfigBuilder#1560

Merged
dOrgJelli merged 1 commit intoorigin-devfrom
kris/build-options-to-builder-interface
Feb 19, 2023
Merged

fix: add BuildOptions to build method in IClientConfigBuilder#1560
dOrgJelli merged 1 commit intoorigin-devfrom
kris/build-options-to-builder-interface

Conversation

@krisbitney
Copy link
Copy Markdown
Contributor

This makes it possible to add a custom cache or resolver without casting.

Before:

const builder: IClientConfigBuilder = new ClientConfigBuilder().addInterface(...);
const config = (builder as ClientConfigBuilder).build(resolver);

After:

const builder: IClientConfigBuilder = new ClientConfigBuilder().addInterface(...);
const config = builder.build(resolver);

Copy link
Copy Markdown
Contributor

@Niraj-Kamdar Niraj-Kamdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@cbrzn cbrzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought about this, and I am not sure if we want this. the reason is that (imo) we don't want the interface to be aware of our implementation details. If someone wants to implement its builder, he probably needs to implement the build method with our options (or with no options at all).

for example (iiuc), this piece of code will throw error

export class MyBuilder extends BaseClientConfigBuilder {
  addDefaults(): IClientConfigBuilder {
    return this;
  }
  build(_options?: { custom: string }): CoreClientConfig {
    return {} as CoreClientConfig;
  }
}

edit: I might be wrong tho but just wanted to share my thoughts 😄

@krisbitney
Copy link
Copy Markdown
Contributor Author

i thought about this, and I am not sure if we want this. the reason is that (imo) we don't want the interface to be aware of our implementation details. If someone wants to implement its builder, he probably needs to implement the build method with our options (or with no options at all).

for example (iiuc), this piece of code will throw error

export class MyBuilder extends BaseClientConfigBuilder {
  addDefaults(): IClientConfigBuilder {
    return this;
  }
  build(_options?: { custom: string }): CoreClientConfig {
    return {} as CoreClientConfig;
  }
}

edit: I might be wrong tho but just wanted to share my thoughts 😄

I think this is a bad UX. I thought it was a bug. Maybe we should reconsider how we add a custom cache or custom resolver?

@cbrzn
Copy link
Copy Markdown
Contributor

cbrzn commented Feb 18, 2023

I think this is a bad UX. I thought it was a bug. Maybe we should reconsider how we add a custom cache or custom resolver?

yup, I think this is a code smell that is indicating us that

@dOrgJelli dOrgJelli merged commit c3a41c9 into origin-dev Feb 19, 2023
@dOrgJelli dOrgJelli deleted the kris/build-options-to-builder-interface branch April 10, 2023 16:56
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.

4 participants