Permalink
Browse files

Fix some issues with Request.continue overrides

These overrides have been broken since the type was not a Js.t.
Apparently BuckleScript doesn't enforce matching types when you
specify the return type of a bs.obj. Here we rewrite it using
bs.deriving abstract, adding the Overrides module to Request.
  • Loading branch information...
zploskey committed Sep 8, 2018
1 parent 2c10aa1 commit 5310e36d0fbc45092a98573b67db014d25536ebf
Showing with 87 additions and 28 deletions.
  1. +63 −0 lib/js/src/Request.js
  2. +24 −28 src/Request.re

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -2,6 +2,9 @@ type t = Types.request;

type headers = Js.Dict.t(string);

[@bs.deriving jsConverter]
type method = [ | `GET | `POST | `PATCH | `PUT | `DELETE | `OPTIONS];

type resourceType =
| Document
| Stylesheet
@@ -17,34 +20,6 @@ type resourceType =
| Manifest
| Other;

type overrides = {
.
url: Js.Nullable.t(string),
method_: Js.Nullable.t(string),
postData: Js.Nullable.t(string),
headers: Js.Nullable.t(headers),
};

[@bs.obj]
external makeOverrides:
(
~url: string=?,
~method_: [@bs.string] [
| `GET
| `POST
| `PATCH
| `PUT
| `DELETE
| `OPTIONS
]
=?,
~postData: string=?,
~headers: headers=?,
unit
) =>
overrides =
"";

[@bs.send]
external abort:
(
@@ -71,6 +46,27 @@ external abort:
Js.Promise.t(unit) =
"";

module Overrides = {
[@bs.deriving abstract]
type t = {
[@bs.optional]
url: string,
[@bs.optional] [@bs.as "method"]
method_: string,
[@bs.optional]
postData: string,
[@bs.optional]
headers,
};

let make = (~url=?, ~method_=?, ~postData=?, ~headers=?, ()) => {
let method_ = method_->Belt.Option.map(methodToJs);
t(~url?, ~method_?, ~postData?, ~headers?);
};
};

type overrides = Overrides.t;

[@bs.send]
external continue: (t, ~overrides: overrides=?, unit) => Js.Promise.t(unit) =
"";

0 comments on commit 5310e36

Please sign in to comment.