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

V7: Simplify client configuration and store config privately #656

Merged
merged 2 commits into from Nov 29, 2019

Conversation

bengourley
Copy link
Contributor

The existing configuration routine was laborious and can be simplified to be done in one fell swoop

This is just an implementation detail really – this logic is done internally in each exported notififer – but it removes some methods from the public client interface (making it compliant with the spec).

  var NOTIFIER_DETAILS = { name: 'Bugsnag x', url: 'https://bugsnag.com', version: '0.0' }
- const client = new Client(NOTIFIER_DETAILS)
- client.setOptions(userOpts)
- client.configure(customSchema)
+ const client = new Client(userOpts, schema, NOTIFIER_DETAILS)

One benefit of the configuration being done via the constructor is that we can remove some of the "client not configured" errors – it's now impossible to have an instance of a client that's not configured.

Since loads of unit tests create Clients directly, this changeset is pretty big, but it does end up removing a lot of boilerplate lines from those tests.

The other change in this PR is to store config at client._config (_ to signify that it is private) and remove its public definition from the types to match up with the spec.

let warningMessage = ''

if (opts.endpoints && opts.endpoints.notify && !opts.endpoints.sessions) {
warningMessage += 'notify endpoint is set but sessions endpoint is not. No sessions will be sent.'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's now impossible to get into this state, as of #647

@bugsnagbot
Copy link
Collaborator

bugsnagbot commented Nov 29, 2019

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 39.43 kB 12.00 kB
After 39.02 kB 11.86 kB
± -414 bytes -138 bytes

Generated by 🚫 dangerJS against 8c2eb11

@bengourley bengourley force-pushed the v7-client-config-simplification branch 3 times, most recently from 69d8c07 to 31c7527 Compare November 29, 2019 14:13
Copy link
Contributor

@djskinner djskinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 great API improvement

@@ -53,7 +46,7 @@ describe('plugin: window onerror', () => {
// const client = new Client(VALID_NOTIFIER)
// const payloads = []
// client.setOptions({ apiKey: 'API_KEY_YEAH' })
// client.configure()
// client._configure()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a comment but I think this should be unchanged. Maybe the all commented code needs updating or just removing? Same for other places in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a backlog ticket to convert all these commented out unit tests into maze runner tests.

I'll undo the change.

@@ -64,7 +59,7 @@ describe('plugin: unhandled rejection', () => {
// it('works with DOMExceptions', done => {
// const client = new Client(VALID_NOTIFIER)
// setOptions({ apiKey: 'API_KEY_YEAH' })
// client.configure()
// client._configure()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code as per other comment

@bengourley bengourley force-pushed the v7-client-config-simplification branch from 31c7527 to 8c2eb11 Compare November 29, 2019 14:34
@bengourley bengourley merged commit 90fb001 into v7 Nov 29, 2019
@bengourley bengourley deleted the v7-client-config-simplification branch November 29, 2019 15:05
@bengourley bengourley mentioned this pull request Apr 14, 2020
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants