Skip to content

Commit

Permalink
refactor!: change class names
Browse files Browse the repository at this point in the history
See citation-js/citation-js#91
See babel/babel#10063

BREAKING CHANGE: Changes Response and Request class names
  • Loading branch information
larsgw committed Jun 27, 2020
1 parent 7726904 commit 2e6a9ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
17 changes: 9 additions & 8 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function parseArgs (resource, init) {

const INTERNALS = Symbol('SyncFetch Internals')

class Request extends self.Request {
class SyncRequest extends Request {
constructor (resource, init = {}, body = init.body) {
super(resource, init)
this[INTERNALS] = {
Expand All @@ -71,11 +71,11 @@ class Request extends self.Request {

clone () {
checkBody(this)
return new Request(this.url, this)
return new SyncRequest(this.url, this)
}
}

class Response extends self.Response {
class SyncResponse extends Response {
constructor (body, init = {}) {
body = body ? Buffer.from(body) : null
super(createStream(body), init)
Expand All @@ -96,7 +96,7 @@ class Response extends self.Response {

clone () {
checkBody(this)
return new Response(this[INTERNALS].body, {
return new SyncResponse(this[INTERNALS].body, {
url: this.url,
headers: this.headers,
status: this.status,
Expand All @@ -115,6 +115,7 @@ class Body {

static mixin (prototype) {
for (const name of Object.getOwnPropertyNames(Body.prototype)) {
if (name === 'constructor') { continue }
const desc = Object.getOwnPropertyDescriptor(Body.prototype, name)
Object.defineProperty(prototype, name, { ...desc, enumerable: true })
}
Expand Down Expand Up @@ -176,10 +177,10 @@ function createStream (body) {
})
}

Body.mixin(Request.prototype)
Body.mixin(Response.prototype)
Body.mixin(SyncRequest.prototype)
Body.mixin(SyncResponse.prototype)

syncFetch.Headers = self.Headers
syncFetch.Request = Request
syncFetch.Response = Response
syncFetch.Request = SyncRequest
syncFetch.Response = SyncResponse
module.exports = syncFetch
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function extractContentType (input) {
const _body = Symbol('bodyBuffer')
const _bodyError = Symbol('bodyError')

class Request extends _fetch.Request {
class SyncRequest extends _fetch.Request {
constructor (resource, init = {}) {
const buffer = shared.parseBody(init.body)

Expand All @@ -64,11 +64,11 @@ class Request extends _fetch.Request {

clone () {
checkBody(this)
return new Request(...shared.serializeRequest(this))
return new SyncRequest(...shared.serializeRequest(this))
}
}

class Response extends _fetch.Response {
class SyncResponse extends _fetch.Response {
constructor (body, init, options = {}) {
const {
buffer = shared.parseBody(body),
Expand All @@ -83,7 +83,7 @@ class Response extends _fetch.Response {
clone () {
checkBody(this)
const buffer = Buffer.from(this[_body])
return new Response(
return new SyncResponse(
shared.createStream(buffer),
shared.serializeResponse(this),
{
Expand All @@ -97,6 +97,7 @@ class Response extends _fetch.Response {
class Body {
static mixin (proto) {
for (const name of Object.getOwnPropertyNames(Body.prototype)) {
if (name === 'constructor') { continue }
const desc = Object.getOwnPropertyDescriptor(Body.prototype, name)
Object.defineProperty(proto, name, {
...desc,
Expand Down Expand Up @@ -167,13 +168,13 @@ function defineBodyError (body, error) {
})
}

Body.mixin(Request.prototype)
Body.mixin(Response.prototype)
Object.defineProperties(Request.prototype, { clone: { enumerable: true } })
Object.defineProperties(Response.prototype, { clone: { enumerable: true } })
Body.mixin(SyncRequest.prototype)
Body.mixin(SyncResponse.prototype)
Object.defineProperties(SyncRequest.prototype, { clone: { enumerable: true } })
Object.defineProperties(SyncResponse.prototype, { clone: { enumerable: true } })

fetch.Headers = _fetch.Headers
fetch.FetchError = _fetch.FetchError
fetch.Request = Request
fetch.Response = Response
fetch.Request = SyncRequest
fetch.Response = SyncResponse
module.exports = fetch

0 comments on commit 2e6a9ea

Please sign in to comment.