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

Define type-specific getters for SSRC #2519

Merged
merged 11 commits into from
Apr 4, 2024
Merged

Define type-specific getters for SSRC #2519

merged 11 commits into from
Apr 4, 2024

Conversation

erikeldridge
Copy link
Contributor

@erikeldridge erikeldridge commented Apr 2, 2024

Discussion

RC's existing SDKs define type-specific getters, like getBoolean. These aren't idiomatic for TS/JS, but have a couple advantages:

  • RC param names, values and types are mutable remotely, so a simple object can’t guarantee a strict type for application logic. A formal schema would address this, but feels excessive for the common case. Type-specific methods are consistent with RC's current SDKs and ensure appropriate types for application logic.
  • RC Android and iOS SDKs log events when personalized values are used. A method interface facilitates such additional functionality

This change defines an "internal" src directory for the new ValueImpl class, since we now have three internal classes. We can move the other two in there in a follow-up change.

Testing

Unit tested via npm test. Functionally tested using a test server.

API Changes

Updates the return type of the evaluate method to be a rich object, modeled after the getters on the Web SDK.

constructor(
private readonly source: ValueSource,
private readonly value = ValueImpl.DEFAULT_VALUE_FOR_STRING) { }
asBoolean(): boolean {

Choose a reason for hiding this comment

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

should we have a 'DEFAULT_VALUE_FOR_BOOLEAN' for the static behavior? Similar to https://github.com/firebase/firebase-js-sdk/blob/master/packages/remote-config/src/value.ts#L36-L39?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it's inconsistent, but given the default value is an empty string when the source is static, BOOLEAN_TRUTHY_VALUES.indexOf(this.value.toLowerCase()) will return false, so I'm not seeing a technical need ... That said, I can imagine how explicitly defining the default value for boolean would make our system easier to understand, so I'll make the change.

Copy link
Member

@lahirumaramba lahirumaramba left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

* @internal
*/
export class ValueImpl implements Value {
public static BOOLEAN_TRUTHY_VALUES = ['1', 'true', 't', 'yes', 'y', 'on'];
Copy link
Member

Choose a reason for hiding this comment

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

should we mark these as readonly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Will do.

/**
* Defines the format for in-app default parameter values.
*/
export type DefaultConfig = { [key: string]: string | number | boolean };
Copy link
Member

Choose a reason for hiding this comment

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

Could this also contain object or Value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add object. I think it'd pair well with a getObject<T>, so those could be the same review. I think it'd be safe to add these after the initial launch.

I don't think Value would make sense because it's a tuple of the string value and an indication of where it came from (the "source"). If the customer is setting it, then the its source will always be "default". Setting a string value in defaultConfig accomplishes the same thing in a more user-friendly way.

Per discussion on the PR, explicitly defining the default boolean
value is more readable.
@erikeldridge erikeldridge merged commit 8dbf86f into ssrc Apr 4, 2024
5 checks passed
@erikeldridge erikeldridge deleted the ssrc-getters branch April 4, 2024 22:03
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.

None yet

4 participants