-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,6 +137,7 @@ const Flagsmith = class { | |
}; | ||
if (identifier) { | ||
this.evaluationContext.identity.identifier = identifier; | ||
this.identity = identifier; | ||
} | ||
} | ||
this.flags = flags; | ||
|
@@ -277,6 +278,7 @@ const Flagsmith = class { | |
flags:IFlags|null= null | ||
getFlagInterval: NodeJS.Timer|null= null | ||
headers?: object | null= null | ||
identity:string|null|undefined = null | ||
initialised= false | ||
oldFlags:IFlags|null= null | ||
onChange:IInitConfig['onChange']|null= null | ||
|
@@ -439,7 +441,7 @@ const Flagsmith = class { | |
const onRetrievedStorage = async (error: Error | null, res: string | null) => { | ||
if (res) { | ||
let flagsChanged = null | ||
let traitsChanged = null | ||
const traitsChanged = null | ||
try { | ||
const json = JSON.parse(res) as IState; | ||
let cachePopulated = false; | ||
|
@@ -563,6 +565,7 @@ const Flagsmith = class { | |
} | ||
|
||
identify(userId?: string | null, traits?: ITraits, transient?: boolean) { | ||
this.identity = userId | ||
this.evaluationContext.identity = { | ||
identifier: userId, | ||
transient: transient, | ||
|
@@ -591,6 +594,7 @@ const Flagsmith = class { | |
flags: this.flags, | ||
ts: this.ts, | ||
evaluationContext: this.evaluationContext, | ||
identity: this.identity, | ||
evaluationEvent: this.evaluationEvent, | ||
} as IState | ||
} | ||
|
@@ -602,11 +606,13 @@ const Flagsmith = class { | |
this.flags = state.flags || this.flags; | ||
this.evaluationContext = state.evaluationContext || this.evaluationContext, | ||
this.evaluationEvent = state.evaluationEvent || this.evaluationEvent; | ||
this.identity = this.getContext()?.identity?.identifier | ||
this.log("setState called", this) | ||
} | ||
} | ||
|
||
logout() { | ||
this.identity = null | ||
this.evaluationContext.identity = null; | ||
if (this.initialised) { | ||
return this.getFlags(); | ||
|
@@ -676,6 +682,7 @@ const Flagsmith = class { | |
...evaluationContext, | ||
environment: evaluationContext.environment || this.evaluationContext.environment, | ||
}; | ||
this.identity = this.getContext()?.identity?.identifier | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ![]() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, good point. Yeah we should add this back too |
||
|
||
if (this.initialised) { | ||
return this.getFlags(); | ||
|
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.
How are
null
andundefined
values different? I see we're setting this tonull
on logout, but is that different at all from beingundefined
?If they're the same could simplify this to
string | undefined
?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.
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 existingstring
=> has identitynull
=> no identity for sure