Skip to content

Commit

Permalink
Make Adapter & Persister backwards compatible for implementors
Browse files Browse the repository at this point in the history
The replacement of the static `name` getter for `Adapter` and
`Persister` in Netflix#310 broke custom implementations of these classes
because `id` needed to be overridden. To retain backwards compatibility
we remove the requirement for `id` to be overridden. Instead we delegate
to `name` by default. This does not affect the in-tree implementations.
  • Loading branch information
Thomas Scholtes committed Apr 19, 2020
1 parent 0003c0e commit 673b9c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/@pollyjs/adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export default class Adapter {
return 'adapter';
}

/* eslint-disable-next-line getter-return */
static get id() {
assert('Must override the static `id` getter.');
return this.name;
}

/* eslint-disable-next-line getter-return */
static get name() {
assert('Must override the static `name` getter.');
}


get defaultOptions() {
return {};
}
Expand Down
9 changes: 7 additions & 2 deletions packages/@pollyjs/persister/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export default class Persister {
return 'persister';
}

/* eslint-disable-next-line getter-return */
static get id() {
assert('Must override the static `id` getter.');
return this.name;
}

// NOTE: deprecated in 4.1.0. Remove in 5.0.0
/* eslint-disable-next-line getter-return */
static get name() {
assert('Must override the static `name` getter.');
}

get defaultOptions() {
Expand Down

0 comments on commit 673b9c6

Please sign in to comment.