Skip to content

Commit af2103c

Browse files
committed
Merge branch 'master' into ag/ch22054/readme-polyfills
2 parents d407bb9 + 22491fd commit af2103c

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"jest": "22.4.3",
5757
"jest-junit": "3.6.0",
5858
"jest-localstorage-mock": "2.2.0",
59+
"jsdom": "11.11.0",
5960
"prettier": "1.11.1",
6061
"readline-sync": "1.4.9",
6162
"rimraf": "2.6.2",

src/__tests__/LDClient-test.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,34 @@ describe('LDClient', () => {
896896
});
897897
});
898898

899+
it('updates flag values when the user changes', done => {
900+
const user2 = { key: 'user2' };
901+
const client = LDClient.initialize(envName, user, { bootstrap: {} });
902+
903+
client.on('ready', () => {
904+
client.identify(user2, null, () => {
905+
expect(client.variation('enable-foo')).toEqual(true);
906+
done();
907+
});
908+
909+
getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": {"value": true}}');
910+
});
911+
});
912+
913+
it('yields map of flag values as the result of identify()', done => {
914+
const user2 = { key: 'user2' };
915+
const client = LDClient.initialize(envName, user, { bootstrap: {} });
916+
917+
client.on('ready', () => {
918+
client.identify(user2, null).then(flagMap => {
919+
expect(flagMap).toEqual({ 'enable-foo': true });
920+
done();
921+
});
922+
923+
getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": {"value": true}}');
924+
});
925+
});
926+
899927
it('reconnects to stream if the user changes', done => {
900928
const user2 = { key: 'user2' };
901929
const encodedUser2 = 'eyJrZXkiOiJ1c2VyMiJ9';
@@ -911,7 +939,7 @@ describe('LDClient', () => {
911939
done();
912940
});
913941

914-
getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": true}');
942+
getLastRequest().respond(200, { 'Content-Type': 'application/json' }, '{"enable-foo": {"value": true}}');
915943
});
916944
});
917945

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ declare module 'ldclient-js' {
220220
* @param onDone
221221
* A callback to invoke after the user is identified.
222222
*/
223-
identify: (user: LDUser, hash?: string, onDone?: () => void) => Promise<void>;
223+
identify: (user: LDUser, hash?: string, onDone?: (err: Error | null, flags: LDFlagSet | null) => void) => Promise<void>;
224224

225225
/**
226226
* Flushes pending events asynchronously.

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export function initialize(env, user, options = {}) {
140140
if (settings) {
141141
updateSettings(settings);
142142
}
143-
resolve(settings);
143+
resolve(utils.transformVersionedValuesToValues(settings));
144144
if (subscribedToChangeEvents) {
145145
connectStream();
146146
}

src/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ export function transformValuesToVersionedValues(flags) {
7676
return ret;
7777
}
7878

79+
/**
80+
* Converts the internal flag state map to a simple map of flag keys to values.
81+
*/
82+
export function transformVersionedValuesToValues(flagsState) {
83+
const ret = {};
84+
for (const key in flagsState) {
85+
if (flagsState.hasOwnProperty(key)) {
86+
ret[key] = flagsState[key].value;
87+
}
88+
}
89+
return ret;
90+
}
91+
7992
/**
8093
* Returns an array of event groups each of which can be safely URL-encoded
8194
* without hitting the safe maximum URL length of certain browsers.

0 commit comments

Comments
 (0)