Skip to content

Commit

Permalink
clean up warnings and remove rebase dep
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyvetter committed Feb 21, 2018
1 parent e184d24 commit 07bf3b7
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 48 deletions.
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name" : "reason-tools",
"version": "0.0.0",
"reason" : {"react-jsx" : 2},
"bs-dependencies": ["reason-react", "rebase"],
"bs-dependencies": ["reason-react"],
"sources": {
"dir": "src",
"subdirs": [
Expand Down
8 changes: 4 additions & 4 deletions docs/Popup.bundle.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
"react-codemirror2": "^4.0.0",
"react-copy-to-clipboard": "^5.0.1",
"react-dom": "^16.0.0",
"reason-react": "^0.3.0",
"rebase": "glennsl/rebase#v0.0.2"
"reason-react": "^0.3.0"
},
"devDependencies": {
"bs-platform": "^2.1.0",
"bs-platform": "^2.2.1",
"chrome-store-api": "^1.0.5",
"file-loader": "^1.1.5",
"generate-json-webpack-plugin": "^0.2.1",
Expand Down
8 changes: 3 additions & 5 deletions src/extension/background.re
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
open Rebase;

open Core;

module Refmt = {
let refmt = Refmt2.refmtJS;
let parse =
fun
| ("Failure", error) => Error(error)
| ("Failure", error) => Protocol.Error(error)
| (conversion, outText) =>
switch (conversion |> Js.String.split("to")) {
| [|inLang, outLang|] when Protocol.languageOfString(outLang) != RefmtShared.UnknownLang =>
Ok(
Protocol.Ok(
Protocol.Refmt.{
outText,
inLang: Protocol.languageOfString(inLang),
outLang: Protocol.languageOfString(outLang)
}
)
| _ => Error(outText)
| _ => Protocol.Error(outText)
};
};

Expand Down
8 changes: 5 additions & 3 deletions src/extension/common/protocol.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
open Rebase;

open Common;

type result('a, 'e) =
| Ok('a)
| Error('e);

type language = RefmtShared.language;

type codeType = RefmtShared.codeType;
Expand Down Expand Up @@ -122,7 +124,7 @@ module Storage = {
let queryDisabled = (callback: bool => unit) =>
Chrome.Storage.Local.get(
"disabled",
(response) => response##disabled |> Js.Undefined.to_opt |> Option.getOr(false) |> callback
(response) => response##disabled |> Js.Undefined.toOption |> Js.Option.getWithDefault(false) |> callback
);
let setDisabled = (value: bool) => Chrome.Storage.Local.set({"disabled": value});
let onDisabledChanged = (callback: bool => unit) =>
Expand Down
8 changes: 4 additions & 4 deletions src/extension/common/vendor/codeMirror.re
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ let make =
| Some(true) => Js.true_
| Some(false) | None => Js.false_
},
"style": Js.Undefined.from_opt(style),
"value": Js.Undefined.from_opt(value),
"style": Js.Undefined.fromOption(style),
"value": Js.Undefined.fromOption(value),
"onBeforeChange": (_editor, _data, value) => switch (onChange) {
| Some(onChange) => onChange(value)
| None => ()
},
"editorDidMount": Js.Undefined.from_opt(editorDidMount),
"options": Js.Undefined.from_opt(options)
"editorDidMount": Js.Undefined.fromOption(editorDidMount),
"options": Js.Undefined.fromOption(options)
},
children
);
2 changes: 1 addition & 1 deletion src/extension/content/convert/detect.re
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let isWhitelisted = () => getWhitelist() |> List.mem(getSignificantUrl());
let isBlacklisted = () => getBlacklist() |> List.mem(getSignificantUrl());

let shouldConvert = () => {
let cached: option(bool) = [%raw "window._rtShouldConvert"] |> Js.Undefined.to_opt;
let cached: option(bool) = [%raw "window._rtShouldConvert"] |> Js.Undefined.toOption;
switch cached {
| Some(shouldConvert) => shouldConvert
| None =>
Expand Down
4 changes: 2 additions & 2 deletions src/extension/content/convert/retrieve.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type listing = {
};

let getTypeTable = (pre) =>
switch (Js.Null.to_opt(Element.nextElementSibling(pre))) {
switch (Js.Null.toOption(Element.nextElementSibling(pre))) {
| None => None
| Some(el) =>
if (Js.to_bool(DOMTokenList.contains(Element.classList(el), "typetable"))) {
let text = Element.innerText(el);
switch (Js.Null.to_opt(Element.nextSibling(el))) {
switch (Js.Null.toOption(Element.nextSibling(el))) {
| None => Some({el, text, remove: () => Element.remove(el)})
| Some(next) =>
if (Node.nodeType(next) == Node._TEXT_NODE) {
Expand Down
8 changes: 3 additions & 5 deletions src/extension/content/convertPage.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Rebase;

open LocalDom;

open Common;
Expand All @@ -18,7 +16,7 @@ let swapStyleSheets = (_) => {
};

let readjustViewport = () =>
if (! Str.isEmpty(Location.hash)) {
if (! (Location.hash == "")) {
[%bs.raw {| window.location.href = window.location.href |}]
};

Expand All @@ -31,8 +29,8 @@ let doListing = (mode, state, listing) => {
text,
(response) => {
switch response {
| Error(_) => () /* TODO */
| Ok({outText}) => Replace.replaceListing(els, outText, replace)
| Protocol.Error(_) => () /* TODO */
| Protocol.Ok({outText}) => Replace.replaceListing(els, outText, replace)
};
/* we're in an async callback, so keep track of when we're finished by keeping count */
state.remaining = state.remaining - 1;
Expand Down
6 changes: 2 additions & 4 deletions src/extension/page.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
open LocalDom;

open Rebase;

let onOpen: string => unit = [%bs.raw
{|
function (hash) {
Expand All @@ -28,8 +26,8 @@ let refmt =
~outLang,
(error) =>
switch error {
| Error(error) => cb(error, RefmtShared.UnknownLang, RefmtShared.UnknownLang)
| Ok({outText, inLang, outLang}) => cb(outText, inLang, outLang)
| Protocol.Error(error) => cb(error, RefmtShared.UnknownLang, RefmtShared.UnknownLang)
| Protocol.Ok({outText, inLang, outLang}) => cb(outText, inLang, outLang)
}
);
Protocol.Storage.setLatestInput(input)
Expand Down
19 changes: 12 additions & 7 deletions src/extension/popup.re
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
open Rebase;

open Core;

open LocalDom;

let mapOrElse = (resolve, reject, item) =>
switch (item) {
| Some(res) => resolve(res)
| None => reject()
};

let getSelection = () =>
Promise.make(
(resolve, reject) =>
Chrome.Tabs.executeScript(
{"code": "window.getSelection().toString()"},
(maybeMaybeArray) =>
(maybeMaybeArray) => {
maybeMaybeArray
|> Js.Null_undefined.to_opt
|> Option.andThen((maybeArray) => Js.Array.findi((_, index) => index === 0, maybeArray))
|> Option.andThen((s) => Str.isEmpty(s) ? None : Some(s))
|> Option.mapOrElse(resolve, reject)
|> Js.Option.andThen([@bs](maybeArray) => Js.Array.findi((_, index) => index === 0, maybeArray))
|> Js.Option.andThen([@bs](s) => s == "" ? None : Some(s))
|> mapOrElse(resolve, reject);
}
)
);

let getLatestInput = () =>
Promise.make(
(resolve, reject) =>
Protocol.Storage.queryLatestInput(
(maybeInput) => maybeInput |> Option.mapOrElse(resolve, reject)
(maybeInput) => maybeInput |> mapOrElse(resolve, reject)
)
);

Expand Down
4 changes: 1 addition & 3 deletions src/extension/popup/popupCommon.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
open Rebase;

open Core;

[%bs.raw {|require('../../../../../src/popup.html')|}];
Expand Down Expand Up @@ -32,7 +30,7 @@ let generateShareableLink = (text) => "https://reasonml.github.io/reason-tools/p

let getInputFromUrl = () => {
let text = LocalDom.Location.hash |> Js.String.sliceToEnd(~from=1) |> Util.atob;
if (Str.isEmpty(text)) {
if (text == "") {
Promise.reject()
} else {
Promise.resolve(text)
Expand Down
1 change: 0 additions & 1 deletion src/refmt/refmt2.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open Rebase;
open RefmtShared;

[@bs.module "../../../../src/refmt/refmt.js"] external parseREEx : string => ast = "parseRE";
Expand Down
6 changes: 1 addition & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ browserify-zlib@^0.2.0:
dependencies:
pako "~1.0.5"

bs-platform@^2.1.0:
bs-platform@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-2.2.1.tgz#e22b82143a43a10630d7b2040aab87648b12190c"

Expand Down Expand Up @@ -1575,10 +1575,6 @@ reason-react@^0.3.0:
react ">=15.0.0 || >=16.0.0"
react-dom ">=15.0.0 || >=16.0.0"

rebase@glennsl/rebase#v0.0.2:
version "0.0.1"
resolved "https://codeload.github.com/glennsl/rebase/tar.gz/a532b99a2978f8cbc4336344dcbc818d567b2149"

regex-cache@^0.4.2:
version "0.4.4"
resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd"
Expand Down

0 comments on commit 07bf3b7

Please sign in to comment.