Skip to content

Commit

Permalink
Cache react-fetch results in the Node version (#20407)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Dec 8, 2020
1 parent cdae31a commit b9680ae
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/react-fetch/src/ReactFetchNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function Response(nativeResponse) {
this.url = nativeResponse.url;

this._response = nativeResponse;
this._blob = null;
this._json = null;
this._text = null;

Expand Down Expand Up @@ -151,12 +150,22 @@ Response.prototype = {
throw new Error('Not implemented.');
},
json() {
if (this._json !== null) {
return this._json;
}
const buffer = readResult(this._result);
return JSON.parse(buffer.toString());
const json = JSON.parse(buffer.toString());
this._json = json;
return json;
},
text() {
if (this._text !== null) {
return this._text;
}
const buffer = readResult(this._result);
return buffer.toString();
const text = buffer.toString();
this._text = text;
return text;
},
};

Expand Down

0 comments on commit b9680ae

Please sign in to comment.