Skip to content

Commit a5f53ca

Browse files
committed
3.1.0 fix setTrait(s) calls prior to identify
Signed-off-by: kyle-ssg <kyle@solidstategroup.com>
1 parent 6e420ad commit a5f53ca

File tree

14 files changed

+62
-15
lines changed

14 files changed

+62
-15
lines changed

flagsmith-core.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ const Flagsmith = class {
5454
const { onChange, onError, identity, api } = this;
5555
let resolved = false;
5656
const handleResponse = ({ flags: features, traits }, segments) => {
57-
this.withTraits = false;
57+
if (identity) {
58+
this.withTraits = false;
59+
}
5860
// Handle server response
5961
let flags = {};
6062
let userTraits = {};
@@ -111,6 +113,7 @@ const Flagsmith = class {
111113
])
112114
.then((res) => {
113115
// @ts-ignore
116+
this.withTraits = false
114117
handleResponse(res[0], res[1])
115118
if (resolve && !resolved) {
116119
resolved = true;
@@ -215,6 +218,24 @@ const Flagsmith = class {
215218
this.initialised = true;
216219
this.ticks = 10000;
217220

221+
this.log("Initialising with properties",{
222+
environmentID,
223+
api,
224+
headers,
225+
onChange,
226+
cacheFlags,
227+
onError,
228+
defaultFlags,
229+
preventFetch,
230+
enableLogs,
231+
enableAnalytics,
232+
AsyncStorage,
233+
identity,
234+
traits,
235+
_trigger,
236+
state,
237+
angularHttpClient,
238+
}, this)
218239

219240
this.timer = this.enableLogs ? new Date().valueOf() : null;
220241
if (_AsyncStorage) {
@@ -386,7 +407,10 @@ const Flagsmith = class {
386407
identify(userId, traits) {
387408
this.identity = userId;
388409
if(traits) {
389-
this.withTraits = traits;
410+
this.withTraits = {
411+
...(this.withTraits||{}),
412+
...traits
413+
};
390414
}
391415
if (this.initialised) {
392416
return this.getFlags();
@@ -504,6 +528,19 @@ const Flagsmith = class {
504528
console.error(initError("setTrait"))
505529
return
506530
}
531+
const traits = {}
532+
traits[key] = trait_value
533+
if (!this.identity) {
534+
535+
this.withTraits = {
536+
...(this.withTraits||{}),
537+
...traits
538+
};
539+
this.log("Set trait prior to identifying", this.withTraits);
540+
541+
return
542+
}
543+
507544

508545
const body = {
509546
"identity": {
@@ -533,6 +570,16 @@ const Flagsmith = class {
533570
console.error("Expected object for flagsmith.setTraits");
534571
}
535572

573+
if (!this.identity) {
574+
this.withTraits = {
575+
...(this.withTraits||{}),
576+
...traits
577+
};
578+
579+
this.log("Set traits prior to identifying", this.withTraits);
580+
return
581+
}
582+
536583
return this.getJSON(api + 'identities/', "POST", JSON.stringify({
537584
"identifier": identity,
538585
traits: Object.keys(traits).map((k)=>({

flagsmith-es/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith-es/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith-es/isomorphic.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith-es/isomorphic.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith-es/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flagsmith-es",
3-
"version": "3.0.6",
3+
"version": "3.1.0",
44
"description": "Feature flagging to support continuous development. This is an esm equivalent of the standard flagsmith npm module.",
55
"main": "./index.js",
66
"type": "module",

flagsmith/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith/isomorphic.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flagsmith/isomorphic.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)