Skip to content
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

prepare 2.10.1 release #152

Merged
merged 335 commits into from
Apr 23, 2019
Merged
Changes from 1 commit
Commits
Show all changes
335 commits
Select commit Hold shift + click to select a range
c7dbbfd
simplify test code
eli-darkly Nov 21, 2018
f938859
rm no-op line
eli-darkly Nov 21, 2018
c2fe238
less specific assertion
eli-darkly Nov 21, 2018
6e67a0b
use Electron test runner
eli-darkly Nov 21, 2018
866bef9
linter
eli-darkly Nov 21, 2018
1587282
add tests for localStorage wrapper in ldclient-js
eli-darkly Nov 21, 2018
3f439ce
use newer Node in CI (since test code uses async)
eli-darkly Nov 21, 2018
0528eaf
linter
eli-darkly Nov 21, 2018
c22dcd0
set up CI environment so Electron can run
eli-darkly Nov 21, 2018
38b2152
rearrange commands so xvfb will be running when we need it
eli-darkly Nov 21, 2018
8267460
fix xvfb command again
eli-darkly Nov 21, 2018
8fffe9a
revert formatting change
eli-darkly Nov 21, 2018
7246704
misc fixes
eli-darkly Nov 22, 2018
aaa3a0f
Merge pull request #125 from launchdarkly/eb/ch27026/eventsource-config
eli-darkly Nov 22, 2018
0101947
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Nov 22, 2018
d6b2d68
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Nov 22, 2018
800999b
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Nov 22, 2018
9581a12
Merge branch 'master' into electron
eli-darkly Nov 22, 2018
dda6728
Merge branch 'electron' into el12-electron-storage
eli-darkly Nov 22, 2018
04dfa82
various dependency fixes
eli-darkly Nov 22, 2018
f14eb6c
Merge branch 'electron' into el12-electron-storage
eli-darkly Nov 22, 2018
ee7ceaf
add package-lock
eli-darkly Nov 24, 2018
0786a48
allow streaming mode to be decoupled from event subscription
eli-darkly Nov 24, 2018
bb29194
misc cleanup
eli-darkly Nov 24, 2018
ad873d5
support REPORT mode for streams in Electron
eli-darkly Nov 24, 2018
f8442c0
linter
eli-darkly Nov 24, 2018
9657073
mechanism for keeping renderer process client in sync with main proce…
eli-darkly Nov 26, 2018
cbd5da6
fix CJS build problem
eli-darkly Nov 26, 2018
3e44778
fix comment
eli-darkly Nov 26, 2018
4fbd0f7
always set flag
eli-darkly Nov 26, 2018
1dccda9
linter
eli-darkly Nov 26, 2018
b5a4c1d
build debugging
eli-darkly Nov 26, 2018
b6de599
add missing dependency
eli-darkly Nov 26, 2018
356656d
Revert "build debugging"
eli-darkly Nov 26, 2018
5d116db
revert unnecessary Rollup config changes
eli-darkly Nov 26, 2018
aa9a748
syntax error
eli-darkly Nov 26, 2018
9264073
Merge pull request #126 from launchdarkly/el12-electron-storage
eli-darkly Nov 27, 2018
45e379e
Merge pull request #128 from launchdarkly/el13-electron-eventsource
eli-darkly Nov 27, 2018
7d01d46
Merge branch 'electron' into el14-pairing
eli-darkly Nov 27, 2018
a394c19
Merge pull request #130 from launchdarkly/el14-pairing
eli-darkly Nov 27, 2018
624afa8
expand unit test to make sure off() really works
eli-darkly Nov 27, 2018
24bb4c4
linter
eli-darkly Nov 27, 2018
4bba83f
simplify code using spread operator
eli-darkly Nov 27, 2018
e15b202
Merge pull request #127 from launchdarkly/eb/ch25474-ch18940/change-e…
eli-darkly Nov 27, 2018
525ca37
fire change event when updating flags after bootstrap from localstorage
eli-darkly Nov 27, 2018
af0fcfc
linter
eli-darkly Nov 27, 2018
45fc561
Merge pull request #131 from launchdarkly/eb/ch27394/change-event-aft…
eli-darkly Nov 27, 2018
c66bbd3
Merge branch 'master' into electron
eli-darkly Nov 28, 2018
45f32af
use published eventsource fork
eli-darkly Nov 28, 2018
a01970e
trying to determine why ES constructor isn't working
eli-darkly Nov 28, 2018
55b9e6e
add end-to-end tests for event source
eli-darkly Nov 28, 2018
b424fab
linter
eli-darkly Nov 28, 2018
73c4eb2
Merge pull request #132 from launchdarkly/eb/ch27429/eventsource-fork
eli-darkly Nov 28, 2018
7aff7f0
funnel analytics events from renderer processes into main process client
eli-darkly Nov 28, 2018
b855966
clarify logic
eli-darkly Nov 28, 2018
5590fe0
disallow identify() when client is synced with another client
eli-darkly Nov 28, 2018
41b1b2e
fix typos
brooswit Nov 29, 2018
84441c2
Merge pull request #135 from launchdarkly/jw/ch27493/readme-typos
Nov 29, 2018
b4008c7
create logging interface, use winston logging in Electron
eli-darkly Nov 29, 2018
96ae69c
expose logger for constructors
eli-darkly Nov 29, 2018
a4e07d4
use deep compare to decide whether a flag value has changed
eli-darkly Nov 29, 2018
bb6ae36
add Node SDK emulation mode in Electron
eli-darkly Nov 29, 2018
e296c74
rm unused import
eli-darkly Nov 29, 2018
929e079
use correct promise/callback semantics
eli-darkly Nov 29, 2018
c0936bd
Merge branch 'master' into electron
eli-darkly Nov 29, 2018
231df47
Merge branch 'electron' into eb/ch27413/disable-identify
eli-darkly Nov 30, 2018
63a1b16
Merge branch 'eb/ch27413/disable-identify' into eb/ch27471/logging
eli-darkly Nov 30, 2018
dcf59a0
Merge branch 'eb/ch27471/logging' into eb/ch27414/node-wrapper
eli-darkly Nov 30, 2018
097896e
Merge pull request #137 from launchdarkly/eb/ch27500/deep-equals
eli-darkly Nov 30, 2018
cf1c388
Merge pull request #134 from launchdarkly/eb/ch27413/disable-identify
eli-darkly Nov 30, 2018
6d533f0
Merge branch 'electron' into eb/ch27471/logging
eli-darkly Nov 30, 2018
a81869c
Merge branch 'master' into electron
eli-darkly Nov 30, 2018
3444c59
Merge branch 'electron' into eb/ch27471/logging
eli-darkly Nov 30, 2018
9c74b1d
fix merge error
eli-darkly Nov 30, 2018
1b64d7b
Merge branch 'electron' into eb/ch27471/logging
eli-darkly Nov 30, 2018
0ff178f
Merge branch 'electron' into eb/ch27412/electron-events
eli-darkly Nov 30, 2018
bc6fcfe
Merge branch 'eb/ch27471/logging' into eb/ch27414/node-wrapper
eli-darkly Nov 30, 2018
19425e0
fix merge
eli-darkly Nov 30, 2018
174d1aa
capitalize original function name
eli-darkly Nov 30, 2018
f06d2d2
Merge branch 'eb/ch27471/logging' into eb/ch27414/node-wrapper
eli-darkly Nov 30, 2018
e2f95e1
update TypeScript defs for all client variants
eli-darkly Nov 30, 2018
c278a2e
rm unused
eli-darkly Nov 30, 2018
5fa2046
update readmes, misc fixes
eli-darkly Dec 1, 2018
7b6e47c
explanation of Node mode
eli-darkly Dec 1, 2018
50ca30a
Rename ConsoleLogger.js to consoleLogger.js
eli-darkly Dec 1, 2018
6797c2a
fix function name
eli-darkly Dec 1, 2018
08f58a2
Merge branch 'eb/ch27502/typescript' of github.com:launchdarkly/js-cl…
eli-darkly Dec 1, 2018
81fed16
rm unused variable
eli-darkly Dec 1, 2018
697ab25
describe Do Not Track
eli-darkly Dec 3, 2018
dd10283
misc fixes
eli-darkly Dec 3, 2018
f26a113
CI diagnostic output
eli-darkly Dec 3, 2018
828730b
Merge pull request #133 from launchdarkly/eb/ch27412/electron-events
eli-darkly Dec 3, 2018
311fcf1
Merge branch 'electron' into eb/ch27471/logging
eli-darkly Dec 3, 2018
0670f77
Merge pull request #136 from launchdarkly/eb/ch27471/logging
eli-darkly Dec 3, 2018
da99064
rename the Node adapter function and simplify how it works
eli-darkly Dec 3, 2018
f3f3ab6
Merge pull request #138 from launchdarkly/eb/ch27414/node-wrapper
eli-darkly Dec 3, 2018
3345d72
Merge branch 'electron' into eb/ch27502/typescript
eli-darkly Dec 3, 2018
d5a83f7
updates for renamed function
eli-darkly Dec 3, 2018
5f96d21
fix test
eli-darkly Dec 3, 2018
f32d048
Merge pull request #139 from launchdarkly/eb/ch27502/typescript
eli-darkly Dec 3, 2018
48e60c5
comments
eli-darkly Dec 3, 2018
18f3489
Merge branch 'eb/debug-build' into electron
eli-darkly Dec 3, 2018
1541d44
rename initializeMain() to be consistent with initializeInRenderer()
eli-darkly Dec 3, 2018
94c170a
Merge pull request #140 from launchdarkly/eb/rename-init
eli-darkly Dec 3, 2018
28cfa7c
add method def
eli-darkly Dec 3, 2018
8775d58
Merge branch 'electron' of github.com:launchdarkly/js-client-private …
eli-darkly Dec 3, 2018
a5603c6
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Dec 3, 2018
8371e0c
Merge branch 'master' of github.com:launchdarkly/js-client-private in…
eli-darkly Dec 3, 2018
71d6811
v2.9.0-alpha.1
eli-darkly Dec 3, 2018
bbf63b4
2.9.0 changelog
eli-darkly Dec 3, 2018
a9c1132
add concurrency flag so lerna won't consume so much memory in CI
eli-darkly Dec 4, 2018
64a33d6
rm debug output
eli-darkly Dec 4, 2018
7835cff
fix Electron client synchronization problem
eli-darkly Dec 5, 2018
b7f7d88
linter
eli-darkly Dec 5, 2018
373def2
test comment
eli-darkly Dec 5, 2018
ef2c7e5
Merge pull request #141 from launchdarkly/eb/fix-client-sync
eli-darkly Dec 5, 2018
91beee6
v2.9.0-alpha.2
eli-darkly Dec 5, 2018
ecf63fd
minor readme edit
eli-darkly Dec 6, 2018
af2afd6
add debug logging for various things
eli-darkly Dec 6, 2018
6b04f4b
linter
eli-darkly Dec 6, 2018
c7542a0
use different User-Agent for Electron
eli-darkly Dec 6, 2018
efc137b
Merge pull request #143 from launchdarkly/eb/ch27930/user-agent
eli-darkly Dec 6, 2018
967ce7c
Merge branch 'electron' of github.com:launchdarkly/js-client-private …
eli-darkly Dec 6, 2018
6ba6272
fix how logger is passed around
eli-darkly Dec 6, 2018
797d7e7
don't send extra feature events when getting flags from Electron main…
eli-darkly Dec 6, 2018
465e55b
add tests for events from allFlags()
eli-darkly Dec 6, 2018
ba3b861
Merge pull request #142 from launchdarkly/eb/debug-logging
eli-darkly Dec 7, 2018
36ca531
Merge pull request #144 from launchdarkly/eb/ch27412/dedup-events
eli-darkly Dec 7, 2018
15fea55
final readme updates for beta
eli-darkly Dec 7, 2018
96a3e0b
Merge pull request #145 from launchdarkly/eb/more-readme
eli-darkly Dec 7, 2018
17d2304
v2.9.0-beta.1
eli-darkly Dec 7, 2018
5b59330
remove ldclient-electron package
eli-darkly Jan 29, 2019
c74d952
update build
eli-darkly Jan 29, 2019
b9e9f21
update readmes
eli-darkly Jan 29, 2019
96e9293
rm extra readme
eli-darkly Jan 29, 2019
a0d22cb
Merge pull request #151 from launchdarkly/eb/30755/remove-electron
eli-darkly Jan 31, 2019
a475650
React SDK from Electron (#149)
yusinto Jan 31, 2019
6936c32
reorganize readme content into 3 files
eli-darkly Feb 1, 2019
a94be76
add doc links
eli-darkly Feb 1, 2019
30bc775
don't mention props and HOCs
eli-darkly Feb 1, 2019
6d7407c
revise JS SDK vs. React features
eli-darkly Feb 1, 2019
1636857
reorganize readmes again
eli-darkly Feb 2, 2019
6ec82bc
Merge pull request #152 from launchdarkly/eb/ch31024/readmes
eli-darkly Feb 2, 2019
2269065
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Feb 6, 2019
907926b
misc copyedits to TS docs + add TypeDoc build script
eli-darkly Feb 7, 2019
875f012
fix event listener signature
eli-darkly Feb 7, 2019
648e7c2
add comment about exports
eli-darkly Feb 7, 2019
5b7607f
fix TypeDoc build to include types from the common package
eli-darkly Feb 7, 2019
e4e8d09
ensure temp directory exists
eli-darkly Feb 7, 2019
9478191
add comment for version property
eli-darkly Feb 8, 2019
12caebd
LDUser can be a type, not an interface
eli-darkly Feb 8, 2019
49bf19d
simplify file-combining logic so common file doesn't need special del…
eli-darkly Feb 8, 2019
d972f3d
ensure that build happens before publish
eli-darkly Feb 8, 2019
73391e4
Merge pull request #156 from launchdarkly/eb/ch31735/publish-react
eli-darkly Feb 8, 2019
5f63b54
version 2.9.1
eli-darkly Feb 8, 2019
efba7da
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Feb 11, 2019
90f8602
Replace lodash with lodash.camelcase and move react out of dependenci…
yusinto Feb 11, 2019
21e40cb
Merge branch 'master' of github.com:launchdarkly/js-client-private
eli-darkly Feb 11, 2019
1c0900d
Merge branch 'master' into eb/ch30937/docs
eli-darkly Feb 11, 2019
3dfa716
Merge branch 'eb/ch30937/docs' into eb/ch30937/docs-2
eli-darkly Feb 11, 2019
e0fded1
Merge pull request #154 from launchdarkly/eb/ch30937/docs
eli-darkly Feb 11, 2019
13c0956
Merge pull request #155 from launchdarkly/eb/ch30937/docs-2
eli-darkly Feb 11, 2019
b2a3ae7
add release script that releases all packages in js-client
eli-darkly Feb 13, 2019
de95ed1
comments
eli-darkly Feb 13, 2019
87036c3
fix error on out-of-order delete
eli-darkly Feb 14, 2019
f101f2d
linter
eli-darkly Feb 14, 2019
ddbb083
handle security error when we're not allowed to use window.localStorage
eli-darkly Feb 15, 2019
257f561
linter
eli-darkly Feb 15, 2019
b2f1b53
remove iframe handshake code for click event UI
eli-darkly Feb 19, 2019
d61e1b2
Merge pull request #160 from launchdarkly/eb/ch32106/localstorage-error
eli-darkly Feb 19, 2019
ba3dc7f
Merge pull request #158 from launchdarkly/eb/ch32009/release-script
eli-darkly Feb 19, 2019
6b44b00
Merge pull request #161 from launchdarkly/eb/ch32279/remove-click-han…
eli-darkly Feb 19, 2019
3f173ab
Merge pull request #159 from launchdarkly/eb/ch31228/stream-delete-error
eli-darkly Feb 19, 2019
8c2f031
change TS declarations to prefer interfaces over types
eli-darkly Feb 22, 2019
5fef62b
Merge pull request #162 from launchdarkly/eb/ch32565/typescript
eli-darkly Feb 23, 2019
4e4a41f
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Feb 23, 2019
02244c0
Merge branch 'master' of github.com:launchdarkly/js-client-private
eli-darkly Feb 23, 2019
bdef1b6
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Feb 23, 2019
dc5bd52
add missing "secondary" attribute to TS definition for user
eli-darkly Mar 5, 2019
8c996d4
Merge pull request #167 from launchdarkly/eb/ch33446/secondary-attr
eli-darkly Mar 5, 2019
00353d9
add cross-env to test scripts
hroederld Mar 6, 2019
80c4907
Merge pull request #168 from launchdarkly/hr/addcrossenv
hroederld Mar 6, 2019
e1af671
update jest to avoid some vulnerable dependencies
eli-darkly Mar 7, 2019
540db38
update sinon to avoid vulnerable dependency
eli-darkly Mar 7, 2019
e5e394f
update babel-jest to avoid an "npm audit" warning
eli-darkly Mar 7, 2019
7e6f6e2
Merge pull request #171 from launchdarkly/eb/ch33508/deps
eli-darkly Mar 7, 2019
173ec56
Update README.md (#170)
yusinto Mar 11, 2019
fd91889
[ch32994] Fix React SDK bootstrap logic (#169)
yusinto Mar 11, 2019
25fc39e
try Node 11.10.1 to avoid Jest problem
eli-darkly Mar 11, 2019
52d1ac8
Merge pull request #172 from launchdarkly/eb/ch33781/node-version
eli-darkly Mar 11, 2019
b0d7924
update changelog for version 2.9.5
eli-darkly Mar 12, 2019
6bbfbf6
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Mar 12, 2019
a3d54ab
version 2.9.5
eli-darkly Mar 12, 2019
124ba3f
version 2.9.5
eli-darkly Mar 12, 2019
8a8cd80
Merge branch '2.9.5'
eli-darkly Mar 12, 2019
6a22b48
rm -> rimraf
hroederld Mar 26, 2019
507f555
Merge pull request #173 from launchdarkly/hr/ch24812/rmonwindowsfix
hroederld Mar 27, 2019
8b21cdc
add azure pipeline
hroederld Mar 27, 2019
4a55655
Merge pull request #174 from launchdarkly/hr/windowsci
hroederld Mar 27, 2019
904e6b5
coerce user attributes into strings when necessary
eli-darkly Mar 29, 2019
8ffcff1
linter
eli-darkly Mar 29, 2019
caa749e
asyncify tests, simplify HTTP mocking, general cleanup
eli-darkly Mar 30, 2019
5d4c1de
rm unused
eli-darkly Mar 30, 2019
e064a3d
generate keys for anonymous users
eli-darkly Apr 2, 2019
0b04950
fix error handling
eli-darkly Apr 2, 2019
800b756
linter
eli-darkly Apr 2, 2019
2c59c9b
make user key optional in TypeScript defs
eli-darkly Apr 2, 2019
528a2eb
misc cleanup of validateUser
eli-darkly Apr 2, 2019
8fd4fc9
move Promise-wrapping of validateUser, for clarity
eli-darkly Apr 2, 2019
39e1964
linter
eli-darkly Apr 2, 2019
b6bbe01
Merge pull request #175 from launchdarkly/eb/ch35206/stringify-attrs
eli-darkly Apr 3, 2019
e266703
Merge pull request #176 from launchdarkly/eb/async-tests
eli-darkly Apr 5, 2019
39d3dbf
Merge pull request #177 from launchdarkly/eb/ch18858/anon-user-key
eli-darkly Apr 5, 2019
a098f2f
add more general HTTP abstraction, use Promises internally
eli-darkly Apr 9, 2019
ccb0836
eliminate some more uses of callbacks; update tests
eli-darkly Apr 9, 2019
288ea52
linter
eli-darkly Apr 9, 2019
adc301f
rm unused
eli-darkly Apr 9, 2019
e7fdc4e
fix init tests
eli-darkly Apr 9, 2019
9b096e4
fix init tests again
eli-darkly Apr 9, 2019
38d4e75
make stream init logic more reliable
eli-darkly Apr 10, 2019
2832c55
add another HTTP test
eli-darkly Apr 10, 2019
5d39679
better network errors
eli-darkly Apr 11, 2019
bc15c00
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Apr 17, 2019
d258337
Merge branch 'master' into eb/ch35956/http-cleanup
eli-darkly Apr 17, 2019
35eaa2f
Merge pull request #178 from launchdarkly/eb/ch35956/http-cleanup
eli-darkly Apr 17, 2019
0aadc83
refactor to isolate the sync XHR logic; expose close() method
eli-darkly Apr 17, 2019
9039f9f
rm unused
eli-darkly Apr 17, 2019
b88d3cb
fix broken readme links
bwoskow-ld Apr 18, 2019
33a3c8a
absolute links
bwoskow-ld Apr 18, 2019
cfc1326
clarify common package
bwoskow-ld Apr 18, 2019
5ef8675
Merge pull request #182 from launchdarkly/bw/fix-broken-readme-links
bwoskow-ld Apr 18, 2019
2032179
sync requests should never be retried
eli-darkly Apr 19, 2019
da8c8cc
Merge pull request #181 from launchdarkly/eb/ch36705/refactor-sync-xhr
eli-darkly Apr 19, 2019
e88e4a3
add script to publish docs to Github Pages
eli-darkly Apr 19, 2019
b059bb4
can't delete a directory while we're in it
eli-darkly Apr 19, 2019
148c235
fix a GH Pages configuration problem
eli-darkly Apr 19, 2019
b55794b
readme link to generated docs
eli-darkly Apr 19, 2019
dcb39ef
Merge pull request #183 from launchdarkly/eb/ch30937/publish-docs
eli-darkly Apr 19, 2019
c7c4e60
fix uuid dependency, add unit tests for user key
eli-darkly Apr 19, 2019
f827e41
linter
eli-darkly Apr 19, 2019
663b822
rm debugging
eli-darkly Apr 19, 2019
389f236
revert accidental change
eli-darkly Apr 19, 2019
036e31c
revert accidental change
eli-darkly Apr 19, 2019
4d624ab
Merge pull request #184 from launchdarkly/eb/ch18858/uuid-crypto-dep
eli-darkly Apr 19, 2019
25e3bc9
Merge branch 'master' into eb/ch35956/http-headers
eli-darkly Apr 19, 2019
6fb3f94
change HTTP response handling to avoid CORS header errors
eli-darkly Apr 19, 2019
cae70b4
Merge pull request #185 from launchdarkly/eb/ch35956/http-headers
eli-darkly Apr 20, 2019
503bebe
Merge branch 'master' of github.com:launchdarkly/js-client
eli-darkly Apr 20, 2019
8d48889
don't use Promise.finally()
eli-darkly Apr 23, 2019
dae51eb
Merge pull request #187 from launchdarkly/eb/ch37469/no-finally
eli-darkly Apr 23, 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
Prev Previous commit
Next Next commit
allow streaming mode to be decoupled from event subscription
  • Loading branch information
eli-darkly committed Nov 24, 2018

Verified

This commit was signed with the committer’s verified signature. The key has expired.
tvdeyen Thomas von Deyen
commit 0786a481774ea014981dac0bafea241a1c8c2286
8 changes: 8 additions & 0 deletions src/EventEmitter.js
Original file line number Diff line number Diff line change
@@ -32,6 +32,14 @@ export default function EventEmitter() {
}
};

emitter.getEvents = function() {
return Object.keys(events);
};

emitter.getEventListenerCount = function(event) {
return events[event] ? events[event].length : 0;
};

emitter.maybeReportError = function(error) {
if (!error) {
return;
154 changes: 135 additions & 19 deletions src/__tests__/LDClient-streaming-test.js
Original file line number Diff line number Diff line change
@@ -44,37 +44,157 @@ describe('LDClient', () => {

describe('streaming/event listening', () => {
const streamUrl = 'https://clientstream.launchdarkly.com';
const fullStreamUrlWithUser = streamUrl + '/eval/' + envName + '/' + encodedUser;

function streamEvents() {
return sources[`${streamUrl}/eval/${envName}/${encodedUser}`].__emitter._events;
return sources[fullStreamUrlWithUser].__emitter._events;
}

function expectStreamUrlIsOpen(url) {
expect(Object.keys(sources)).toEqual([url]);
}

function expectNoStreamIsOpen() {
expect(sources).toMatchObject({});
}

it('does not connect to the stream by default', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
expect(sources).toMatchObject({});
expectNoStreamIsOpen();
done();
});
});

it('connects to the stream when listening to global change events', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });
it('connects to the stream if options.streaming is true', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {}, streaming: true });

client.on('ready', () => {
client.on('change', () => {});
expect(Object.keys(sources)).toEqual([streamUrl + '/eval/' + envName + '/' + encodedUser]);
expectStreamUrlIsOpen(fullStreamUrlWithUser);
done();
});
});

it('connects to the stream when listening to change event for one flag', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });
describe('setStreaming()', () => {
it('can connect to the stream', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
client.on('change:flagkey', () => {});
expect(Object.keys(sources)).toEqual([streamUrl + '/eval/' + envName + '/' + encodedUser]);
done();
client.on('ready', () => {
client.setStreaming(true);
expectStreamUrlIsOpen(fullStreamUrlWithUser);
done();
});
});

it('can disconnect from the stream', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
client.setStreaming(true);
expectStreamUrlIsOpen(fullStreamUrlWithUser);
client.setStreaming(false);
expectNoStreamIsOpen();
done();
});
});
});

describe('on("change")', () => {
it('connects to the stream if not otherwise overridden', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
client.on('change', () => {});
expectStreamUrlIsOpen(fullStreamUrlWithUser);
done();
});
});

it('also connects if listening for a specific flag', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
client.on('change:flagkey', () => {});
expectStreamUrlIsOpen(fullStreamUrlWithUser);
done();
});
});

it('does not connect if some other kind of event was specified', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
client.on('error', () => {});
expectNoStreamIsOpen();
done();
});
});

it('does not connect if options.streaming is explicitly set to false', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {}, streaming: false });

client.on('ready', () => {
client.on('change', () => {});
expectNoStreamIsOpen();
done();
});
});

it('does not connect if setStreaming(false) was called', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });

client.on('ready', () => {
client.setStreaming(false);
client.on('change', () => {});
expectNoStreamIsOpen();
done();
});
});
});

describe('off("change")', () => {
it('disconnects from the stream if all event listeners are removed', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });
const listener1 = () => {};
const listener2 = () => {};

client.on('ready', () => {
client.on('change', listener1);
client.on('change:flagkey', listener2);
client.on('error', () => {});
expectStreamUrlIsOpen(fullStreamUrlWithUser);

client.off('change', listener1);
expectStreamUrlIsOpen(fullStreamUrlWithUser);

client.off('change:flagkey', listener2);
expectNoStreamIsOpen();

done();
});
});

it('does not disconnect if setStreaming(true) was called', done => {
const client = LDClient.initialize(envName, user, { bootstrap: {} });
const listener1 = () => {};
const listener2 = () => {};

client.on('ready', () => {
client.setStreaming(true);

client.on('change', listener1);
client.on('change:flagkey', listener2);
expectStreamUrlIsOpen(fullStreamUrlWithUser);

client.off('change', listener1);
expectStreamUrlIsOpen(fullStreamUrlWithUser);

client.off('change:flagkey', listener2);
expectStreamUrlIsOpen(fullStreamUrlWithUser);

done();
});
});
});

@@ -83,7 +203,7 @@ describe('LDClient', () => {

client.on('ready', () => {
client.on('change:flagkey', () => {});
expect(Object.keys(sources)).toEqual([streamUrl + '/eval/' + envName + '/' + encodedUser + '?h=' + hash]);
expectStreamUrlIsOpen(fullStreamUrlWithUser + '?h=' + hash);
done();
});
});
@@ -93,9 +213,7 @@ describe('LDClient', () => {

client.on('ready', () => {
client.on('change', () => {});
expect(Object.keys(sources)).toEqual([
streamUrl + '/eval/' + envName + '/' + encodedUser + '?withReasons=true',
]);
expectStreamUrlIsOpen(fullStreamUrlWithUser + '?withReasons=true');
done();
});
});
@@ -105,9 +223,7 @@ describe('LDClient', () => {

client.on('ready', () => {
client.on('change', () => {});
expect(Object.keys(sources)).toEqual([
streamUrl + '/eval/' + envName + '/' + encodedUser + '?h=' + hash + '&withReasons=true',
]);
expectStreamUrlIsOpen(fullStreamUrlWithUser + '?h=' + hash + '&withReasons=true');
done();
});
});
46 changes: 40 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -36,6 +36,8 @@ export function initialize(env, user, options = {}) {
let goalTracker;
let useLocalStorage;
let goals;
let streamActive;
let streamForcedState;
let subscribedToChangeEvents;
let firstEvent = true;

@@ -180,7 +182,7 @@ export function initialize(env, user, options = {}) {
updateSettings(settings);
}
resolve(utils.transformVersionedValuesToValues(settings));
if (subscribedToChangeEvents) {
if (streamActive) {
connectStream();
}
});
@@ -299,6 +301,7 @@ export function initialize(env, user, options = {}) {
}

function connectStream() {
streamActive = true;
if (!ident.getUser()) {
return;
}
@@ -403,9 +406,9 @@ export function initialize(env, user, options = {}) {
}

function on(event, handler, context) {
if (event.substr(0, changeEvent.length) === changeEvent) {
if (isChangeEventKey(event)) {
subscribedToChangeEvents = true;
if (!stream.isConnected()) {
if (!streamActive && streamForcedState === undefined) {
connectStream();
}
emitter.on.apply(emitter, [event, handler, context]);
@@ -415,13 +418,40 @@ export function initialize(env, user, options = {}) {
}

function off(event) {
if (event === changeEvent) {
if ((subscribedToChangeEvents = true)) {
emitter.off.apply(emitter, Array.prototype.slice.call(arguments));
if (isChangeEventKey(event)) {
let haveListeners = false;
emitter.getEvents().forEach(key => {
if (isChangeEventKey(key) && emitter.getEventListenerCount(key) > 0) {
haveListeners = true;
}
});
if (!haveListeners) {
subscribedToChangeEvents = false;
if (streamActive && streamForcedState === undefined) {
streamActive = false;
stream.disconnect();
}
}
}
}

function setStreaming(state) {
const newState = state === null ? undefined : state;
if (newState !== streamForcedState) {
streamForcedState = newState;
let shouldBeStreaming = streamForcedState || (subscribedToChangeEvents && streamForcedState === undefined);
if (shouldBeStreaming && !streamActive) {
connectStream();
} else if (!shouldBeStreaming && streamActive) {
streamActive = false;
stream.disconnect();
}
}
emitter.off.apply(emitter, Array.prototype.slice.call(arguments));
}

function isChangeEventKey(event) {
return event === changeEvent || event.substr(0, changeEvent.length + 1) === changeEvent + ':';
}

function handleMessage(event) {
@@ -565,6 +595,9 @@ export function initialize(env, user, options = {}) {
}

function signalSuccessfulInit() {
if (options.streaming !== undefined) {
setStreaming(options.streaming);
}
emitter.emit(readyEvent);
emitter.emit(successEvent); // allows initPromise to distinguish between success and failure
}
@@ -631,6 +664,7 @@ export function initialize(env, user, options = {}) {
track: track,
on: on,
off: off,
setStreaming: setStreaming,
flush: flush,
allFlags: allFlags,
};
29 changes: 26 additions & 3 deletions typings.d.ts
Original file line number Diff line number Diff line change
@@ -73,9 +73,10 @@ declare module 'ldclient-js' {
* flag value, and the previous value. This is always accompanied by a general
* "change" event as described above; you can listen for either or both.
*
* The "change" and "change:FLAG-KEY" events have special behavior: the client
* will open a streaming connection to receive live changes if and only if you
* are listening for one of these events.
* The "change" and "change:FLAG-KEY" events have special behavior: by default, the
* client will open a streaming connection to receive live changes if and only if
* you are listening for one of these events. This behavior can be overridden by
* setting LDOptions.streaming or calling LDClient.setStreaming().
*/
type LDEventSignature = (
key: string,
@@ -128,6 +129,17 @@ declare module 'ldclient-js' {
*/
streamUrl?: string;

/**
* Whether or not to open a streaming connection to LaunchDarkly for live flag updates.
*
* If this is true, the client will always attempt to maintain a streaming connection; if false,
* it never will. If you leave the value undefined (the default), the client will open a streaming
* connection if you subscribe to "change" or "change:flag-key" events (see LDClient.on()).
*
* This is equivalent to calling client.setStreaming() with the same value.
*/
streaming?: boolean;

/**
* Whether or not to use the REPORT verb to fetch flag settings.
*
@@ -424,6 +436,17 @@ declare module 'ldclient-js' {
*/
variationDetail: (key: string, defaultValue?: LDFlagValue) => LDEvaluationDetail;

/**
* Specifies whether or not to open a streaming connection to LaunchDarkly for live flag updates.
*
* If this is true, the client will always attempt to maintain a streaming connection; if false,
* it never will. If you leave the value undefined (the default), the client will open a streaming
* connection if you subscribe to "change" or "change:flag-key" events (see LDClient.on()).
*
* This can also be set as the "streaming" property of the client options.
*/
setStreaming: (value?: boolean) => void;

/**
* Registers an event listener. See LDEventSignature for the available event types
* and the data that can be associated with them.