Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4aa6b2a
[ch43034] React sdk support for bootstrapping natively
eli-darkly Sep 6, 2019
0a285d4
copyedits
eli-darkly Sep 6, 2019
fd9f921
applying the markdown templates (#3)
bwoskow-ld Sep 10, 2019
25978c6
Reinstate 2.12.5 and 2.13.0 (#4)
bwoskow-ld Sep 10, 2019
559b138
Merge branch 'master' of github.com:launchdarkly/react-client-sdk-pri…
bwoskow-ld Sep 11, 2019
d74ec6e
address pr feedback
bwoskow-ld Sep 11, 2019
a38f444
Add code docs formerly in the readme (#5)
bwoskow-ld Sep 11, 2019
0772399
Added asyncCreateLDProvider react version compatibility to readme. Ad…
yusinto Sep 11, 2019
89d6494
Merge branch 'master' of github.com:launchdarkly/react-client-sdk-pri…
bwoskow-ld Sep 11, 2019
2e1857f
minor doc updates
bwoskow-ld Sep 11, 2019
f5101dc
Renamed asyncCreateLDProvider to asyncWithLDProvider
yusinto Sep 11, 2019
3e9872d
minor doc formatting update
bwoskow-ld Sep 11, 2019
90258d8
Merge pull request #2 from launchdarkly/yus/ch43034/make-react-sdk-su…
yusinto Sep 11, 2019
c118b86
Merge branch 'master' of github.com:launchdarkly/react-client-sdk
eli-darkly Sep 13, 2019
09aca4d
Update package.json
yusinto Sep 26, 2019
417b7fb
Update package.json
yusinto Sep 26, 2019
fd4f948
Merge pull request #7 from launchdarkly/yus/ch50732/update-react-clie…
yusinto Sep 26, 2019
c519208
update JS SDK dependencies + misc build improvements (#8)
eli-darkly Nov 6, 2019
8eb2a6d
merge from public after release
LaunchDarklyCI Nov 6, 2019
07a2295
Merge branch 'master' of github.com:launchdarkly/react-client-sdk
bwoskow-ld Nov 7, 2019
19a4b82
Added isEmpty check on bootstrap object. Use previous values in setSt…
yusinto Nov 9, 2019
fb57c4e
Update asyncWithLDProvider.test.tsx
yusinto Nov 9, 2019
c61f6b3
Fixed errors, warnings and upgrade major packages.
yusinto Nov 9, 2019
8c39968
Merge pull request #11 from launchdarkly/yus/ch55739/fixed-example-er…
yusinto Nov 13, 2019
ed9c348
Rollback bootstrap changes
yusinto Nov 13, 2019
966ff62
Update package.json
yusinto Nov 13, 2019
f95f972
Added tests for bootstrapping from an empty object.
yusinto Nov 13, 2019
e924c9f
Update tslint.json
yusinto Nov 13, 2019
d25bbef
Update yarn.lock
yusinto Nov 13, 2019
51d7d1b
Merge pull request #10 from launchdarkly/yus/ch55738/fix-initial-flag…
yusinto Nov 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/async-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
"dependencies": {
"@babel/polyfill": "^7.2.5",
"express": "^4.16.4",
"launchdarkly-react-client-sdk": "^2.13.0",
"ldclient-node": "^5.7.2",
"launchdarkly-react-client-sdk": "^2.15.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-router-dom": "^4.3.1",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-router-dom": "^5.1.2",
"styled-components": "^4.1.3"
},
"devDependencies": {
Expand All @@ -53,7 +52,7 @@
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"universal-hot-reload": "^3.3.3",
"universal-hot-reload": "^3.3.4",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7",
"webpack-node-externals": "^1.7.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/async-provider/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { hydrate } from 'react-dom';
import { render } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk';
import App from '../universal/app';

(async () => {
const LDProvider = await asyncWithLDProvider({ clientSideID: '59b2b2596d1a250b1c78baa4' });

hydrate(
render(
<BrowserRouter>
<LDProvider>
<App />
Expand Down
3,930 changes: 1,680 additions & 2,250 deletions examples/async-provider/yarn.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions examples/hoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@
"dependencies": {
"@babel/polyfill": "^7.2.5",
"express": "^4.16.4",
"ldclient-node": "^5.7.2",
"launchdarkly-react-client-sdk": "^2.13.0",
"launchdarkly-react-client-sdk": "^2.15.0",
"lodash": "^4.17.11",
"prop-types": "^15.7.2",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-router-dom": "^4.3.1",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-router-dom": "^5.1.2",
"styled-components": "^4.1.3"
},
"devDependencies": {
Expand All @@ -52,7 +51,7 @@
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"universal-hot-reload": "^2.0.1",
"universal-hot-reload": "^3.3.4",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack-node-externals": "^1.7.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/hoc/src/client/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { hydrate } from 'react-dom';
import { render } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import App from '../universal/app';

hydrate(
render(
<BrowserRouter>
<App />
</BrowserRouter>,
Expand Down
9 changes: 8 additions & 1 deletion examples/hoc/src/server/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
const UniversalHotReload = require('universal-hot-reload').default;
UniversalHotReload(require('../../webpack.config.server.js'), require('../../webpack.config.client.js'));

// supply your own webpack configs
const serverConfig = require('../../webpack.config.server.js');
const clientConfig = require('../../webpack.config.client.js');

// the configs are optional, you can supply either one or both.
// if you omit say the server config, then your server won't hot reload.
UniversalHotReload({ serverConfig, clientConfig });
3,996 changes: 1,990 additions & 2,006 deletions examples/hoc/yarn.lock

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion src/asyncWithLDProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ describe('asyncWithLDProvider', () => {
expect(receivedNode).toHaveTextContent('{"another-test-flag":false,"test-flag":false}');
});

test('consecutive flag changes gets stored in context correctly', async () => {
mockLDClient.on.mockImplementationOnce((e: string, cb: (c: LDFlagChangeset) => void) => {
cb({ 'another-test-flag': { current: false, previous: true } });

// simulate second update
cb({ 'test-flag': { current: false, previous: true } });
});

const receivedNode = await renderWithConfig({ clientSideID });

expect(mockLDClient.on).toHaveBeenNthCalledWith(1, 'change', expect.any(Function));
expect(receivedNode).toHaveTextContent('{"testFlag":false,"anotherTestFlag":false}');
});

test('ldClient bootstraps correctly', async () => {
// don't subscribe to changes to test bootstrap
mockLDClient.on.mockImplementation((e: string, cb: (c: LDFlagChangeset) => void) => {
Expand All @@ -113,6 +127,18 @@ describe('asyncWithLDProvider', () => {
expect(receivedNode).toHaveTextContent('{"anotherTestFlag":false,"testFlag":true}');
});

test('ldClient bootstraps with empty flags', async () => {
// don't subscribe to changes to test bootstrap
mockLDClient.on.mockImplementation((e: string, cb: (c: LDFlagChangeset) => void) => {
return;
});
const options: LDOptions = {
bootstrap: {},
};
const receivedNode = await renderWithConfig({ clientSideID, user, options });
expect(receivedNode).toHaveTextContent('{}');
});

test('ldClient bootstraps correctly with kebab-case', async () => {
// don't subscribe to changes to test bootstrap
mockLDClient.on.mockImplementation((e: string, cb: (c: LDFlagChangeset) => void) => {
Expand Down Expand Up @@ -146,7 +172,7 @@ describe('asyncWithLDProvider', () => {
flags: { devTestFlag: true, launchDoggly: true },
ldClient: mockLDClient,
}));
const options: LDOptions = { bootstrap: {} };
const options: LDOptions = {};
const flags = { 'dev-test-flag': false, 'launch-doggly': false };
const receivedNode = await renderWithConfig({ clientSideID, user, options, flags });

Expand Down
5 changes: 3 additions & 2 deletions src/asyncWithLDProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function asyncWithLDProvider(config: ProviderConfig) {
const { bootstrap } = options;
if (bootstrap && bootstrap !== 'localStorage') {
const bootstrappedFlags = reactOptions.useCamelCaseFlagKeys ? camelCaseKeys(bootstrap) : bootstrap;
setLDData({ flags: bootstrappedFlags, ldClient });
setLDData(prev => ({ ...prev, flags: bootstrappedFlags }));
}
}

Expand All @@ -52,7 +52,8 @@ export default async function asyncWithLDProvider(config: ProviderConfig) {
const flagKey = reactOptions.useCamelCaseFlagKeys ? camelCase(key) : key;
flattened[flagKey] = changes[key].current;
}
setLDData({ flags: { ...ldData.flags, ...flattened }, ldClient });

setLDData(prev => ({ ...prev, flags: { ...prev.flags, ...flattened } }));
});
}, []);

Expand Down
12 changes: 12 additions & 0 deletions src/withLDProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ describe('withLDProvider', () => {
expect(mockInitLDClient).toHaveBeenCalledWith(clientSideID, user, defaultReactOptions, options, undefined);
});

test.only('ldClient bootstraps with empty flags', () => {
const user: LDUser = { key: 'yus', name: 'yus ng' };
const options: LDOptions = {
bootstrap: {},
};
const LaunchDarklyApp = withLDProvider({ clientSideID, user, options })(App);
const component = shallow(<LaunchDarklyApp />, { disableLifecycleMethods: true });
const initialState = component.state() as HocState;

expect(initialState.flags).toEqual({});
});

test('ld client is bootstrapped correctly and transforms keys to camel case', () => {
const user: LDUser = { key: 'yus', name: 'yus ng' };
const options: LDOptions = {
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"member-access": false,
"prefer-function-over-method": false,
"no-unbound-method": false,
"no-unused-variable": true,
"no-unused-variable": false,
"comment-format": false
},
"rulesDirectory": []
Expand Down
Loading