feat: improve UX for Typescript app codegen#40
Conversation
There was a problem hiding this comment.
This looks good but I think we could reduce the number of getters for each property. I'm guessing you thought a lot about this so maybe I'm missing something.
Since the getter methods are abstract, the user will always implement them. Since they will always be implemented, I think it would make more sense to just make the properties themselves abstract and public, or to remove the properties altogether and just use the methods.
For example,
// is this._defaultUri redundant?
private _getUri(uri?: string): string {
return uri || this._defaultUri || this._getDefaultUri() || "testimport.uri.eth";
}
// can we do this?
private _getUri(uri?: string): string {
return uri || this._getDefaultUri() || "testimport.uri.eth";
}Other than that question, I think this is very good. It gives the user sane defaults (the likely URI) for the common case, while allowing full customization of an abstract class.
Another suggestion I just thought of: should the class validate the URI it is constructed with? (using client.validate)
|
@krisbitney When using On the other hand, calling By keeping To demonstrate this, let's consider an example scenario with multiple calls to the getter method: // Using _defaultUri in the getter method (with caching)
private _defaultUri: string | undefined;
private _getUri(uri?: string): string {
return uri || this._defaultUri || this._getDefaultUri() || "testimport.uri.eth";
}
// Without _defaultUri in the getter method (no caching)
private _getUri(uri?: string): string {
return uri || this._getDefaultUri() || "testimport.uri.eth";
}
// Example usage
const instance = new MyClass(); // First call - _getDefaultUri() will be executed and result will be cached in _defaultUri
// Subsequent calls - _getDefaultUri() won't be executed again, cached value will be used
const uri1 = instance.uri; // defaultUri
const uri2 = instance._getUri(); // defaultUri
// ...In the first scenario (with caching), In contrast, in the second scenario (without caching), every call to In conclusion, keeping I appreciate you pointing this out though, due to this discussion, I realized that it would be better to have those protected getters as async functions and we may further lazily compute the values during first call and support more use-cases of fetching the needed values asynchronously. |
lol, thanks NirajGPT |
|
For sure! |
dOrgJelli
left a comment
There was a problem hiding this comment.
This PR should point to a new PR in the CLI for the updated template project. This way we know what the e2e looks like.
| /* URI: "testimport.uri.eth" */ | ||
| export const TestImport_Module = { | ||
| importedMethod: async ( | ||
| export abstract class BaseTestImport { |
There was a problem hiding this comment.
This type isn't being used anywhere, is this what the user imports into their code? If so I don't think that's what we want, instead we'd want import { TestImport } from ...
|
Created a PR here @Niraj-Kamdar polywrap/wrap-cli#1855 |
Update App Template: polywrap/wrap-cli#1855