-
Notifications
You must be signed in to change notification settings - Fork 356
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
Add #set and #toJSON to RC ServerTemplate #2522
Conversation
} else { | ||
template.cache = options?.template; | ||
} | ||
template.set(options?.template); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, intuitive reuse of set
👍
const initializedTemplate = remoteConfig.initServerTemplate(); | ||
initializedTemplate.set(template); | ||
const parsed = initializedTemplate.toJSON(); | ||
expect(parsed).deep.equals(template); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very readable 👍
.to.throw(/Failed to parse the JSON string: ([\D\w]*)\./); | ||
}); | ||
|
||
INVALID_PARAMETERS.forEach((invalidParameter) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking: it feels like we're re-testing the cases covered by the tests on ServerTemplateDataImpl
. Looking at the tests, I see us already doing this on the tests for initServerTemplate
and load
. Makes me think there's an opportunity for a later change to extract ServerTemplateDataImpl
to the internal dir so we can test it directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
* Sets and caches a {@link ServerTemplateData} or a JSON string representing | ||
* the server template | ||
*/ | ||
set(template: ServerTemplateDataType): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious (because I think either is fine) so we need a separate type for this or should this just be ServerTemplateData | string
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either works, I originally had it as ServerTemplateData | string
but we are defining it in quite a few places across multiple files, so I moved it to a type 😃
Discussion
Right now, we can set a RC server template via the constructor. Customers, however, would need to update the template multiple times. The current API exposes
template.cache
, but that feels more like an internal detail than an API now.ServerTemplate.cache
asprivate
, and should only be used with-in the classServerTemplate.set
to allow for setting the template or templateJSONServerTemplate.toJSON
to return JSON representation (ServerTemplateData
) of the templateInitServerTemplate
to make use of the new set method.Testing
Added new unit tests for the new
set
method. Update existing tests to make use oftoJSON()
instead of the cache.API Changes
ServerTemplate.cache
is now private and cannot be accessed outside of the classServerTemplate.set
to allow for setting the template or templateJSONServerTemplate.toJSON
to return JSON representation (ServerTemplateData
) of the template