Skip to content

fix: this.identity reverse compatibility #302

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kyle-ssg
Copy link
Member

#240 aimed to introduce a new api for setting client context such as identity/traits whilst being backwards compatible with the current API. This however did introduce a breaking change where flagsmith.identity does not reflect the current context.

Until we make the leap to documenting contexts / suggesting this as the approach to using the SDK, this PR re-adds this for backwards compatibility.

@kyle-ssg kyle-ssg requested review from tiagoapolo and khvn26 March 28, 2025 11:57
@kyle-ssg kyle-ssg linked an issue Mar 28, 2025 that may be closed by this pull request
@@ -269,6 +270,7 @@ const Flagsmith = class {
flags:IFlags|null= null
getFlagInterval: NodeJS.Timer|null= null
headers?: object | null= null
identity:string|null|undefined = null
Copy link
Member

Choose a reason for hiding this comment

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

How are null and undefined values different? I see we're setting this to null on logout, but is that different at all from being undefined?

If they're the same could simplify this to string | undefined?

Copy link

Choose a reason for hiding this comment

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

It's a bit of a "not yet known" versus we explicitely know there are no value. I personally thinks it's better for readability to keep and set to null on purpose when logging out and keep the undefined when initing.
To represent a bit the:
undefined => loading while detecting if null or existing
string => has identity
null => no identity for sure

Copy link

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

@kyle-ssg Just one comment to make sure it's on your radar. Otherwise looks good to me after fixing conflicts

@@ -666,6 +671,7 @@ const Flagsmith = class {
...evaluationContext,
environment: evaluationContext.environment || this.evaluationContext.environment,
};
this.identity = this.getContext()?.identity?.identifier
Copy link

Choose a reason for hiding this comment

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

@kyle-ssg , I saw that identity got removed from the state there. Just want to make sure that for reverse compatibility it wouldn't need flagsmith.getState().identity

image

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.

Identity is empty after executing identify
3 participants