Skip to content

Commit

Permalink
Merge pull request #157 from avivasyuta/remove_formdata_patch
Browse files Browse the repository at this point in the history
remove FormData patching
  • Loading branch information
jpillora authored Aug 19, 2022
2 parents aa2df41 + 4b9d21a commit caf3b91
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 67 deletions.
4 changes: 2 additions & 2 deletions example/fetch-form-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ <h5>Fetch with form data</h5>
console.log("AFTER", request, response);
});
document.getElementById("submit").addEventListener("click", function() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
const data = new FormData();
data.append("username", username);
data.append("password", password);
Expand Down
6 changes: 1 addition & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import headers from "./misc/headers";
//patchable types
import XMLHttpRequest from "./patch/xmlhttprequest";
import fetch from "./patch/fetch";
import FormData from "./patch/formdata";

//global state
import hooks from "./misc/hooks";
Expand All @@ -30,17 +29,14 @@ xhook.after = function(handler, i) {
xhook.enable = function() {
XMLHttpRequest.patch();
fetch.patch();
FormData.patch();
};
xhook.disable = function() {
XMLHttpRequest.unpatch();
fetch.unpatch();
FormData.unpatch();
};
//expose native objects
xhook.XMLHttpRequest = XMLHttpRequest.Native;
xhook.fetch = fetch.Native;
xhook.FormData = FormData.Native;

//expose helpers
xhook.headers = headers.convert;
Expand All @@ -49,4 +45,4 @@ xhook.headers = headers.convert;
xhook.enable();


export default xhook;
export default xhook;
5 changes: 0 additions & 5 deletions src/patch/fetch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { windowRef } from "../misc/window";
import { mergeObjects } from "../misc/events";
import hooks from "../misc/hooks";
import formData from "./formdata";

//browser's fetch
const Native = windowRef.fetch;
Expand All @@ -26,10 +25,6 @@ const Xhook = function(url, options) {
return new Promise(function(resolve, reject) {
let fullfiled = resolve
const getRequest = function() {
if (options.body instanceof formData.Xhook) {
options.body = options.body.fd;
}

if (options.headers) {
options.headers = new Headers(options.headers);
}
Expand Down
50 changes: 0 additions & 50 deletions src/patch/formdata.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/patch/xmlhttprequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "../misc/events";
import { EventEmitter } from "../misc/event-emitter";
import headers from "../misc/headers";
import formData from "./formdata";
import hooks from "../misc/hooks";

const nullify = res => (res === undefined ? null : res);
Expand Down Expand Up @@ -288,10 +287,6 @@ const Xhook = function() {
xhr.setRequestHeader(header, value);
}
}
//extract real formdata
if (request.body instanceof formData.Xhook) {
request.body = request.body.fd;
}
//real send!
xhr.send(request.body);
};
Expand Down

0 comments on commit caf3b91

Please sign in to comment.