Skip to content

Commit

Permalink
"memoize" shouldConvert
Browse files Browse the repository at this point in the history
  • Loading branch information
glennsl authored and rickyvetter committed Apr 18, 2017
1 parent 8639bdc commit 87a0764
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/extension/content/convert/Detect.re
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,28 @@ let isBlacklisted () =>
getBlacklist () |> List.mem (getSignificantUrl ());

let shouldConvert () => {
/*
Js.log @@ "isWhitelisted: " ^ (string_of_bool @@ isWhitelisted ());
Js.log @@ "mightBeOcamlDoc: " ^ (string_of_bool @@ mightBeOcamlDoc ());
Js.log @@ "isBlackListed: " ^ (string_of_bool @@ isBlacklisted ());
Js.log @@ "shouldConvert: " ^ (string_of_bool (isWhitelisted () || (mightBeOcamlDoc () && not (isBlacklisted ()))));
*/
isWhitelisted () || (mightBeOcamlDoc () && not (isBlacklisted ()));
let cached: option bool = [%raw "window._rtShouldConvert"] |> Js.Undefined.to_opt;
switch cached {
| Some shouldConvert => shouldConvert
| None =>
let isWhitelisted = isWhitelisted ();
let mightBeOcamlDoc = mightBeOcamlDoc ();
let isBlacklisted = isBlacklisted ();
let shouldConvert = isWhitelisted || (mightBeOcamlDoc && not isBlacklisted);
/*
Js.log @@ "isWhitelisted: " ^ (string_of_bool isWhitelisted);
Js.log @@ "mightBeOcamlDoc: " ^ (string_of_bool mightBeOcamlDoc);
Js.log @@ "isBlackListed: " ^ (string_of_bool isBlacklisted);
Js.log @@ "shouldConvert: " ^ (string_of_bool shouldConvert);
*/
if shouldConvert {
ignore [%raw "window._rtShouldConvert = 1"];
} else {
ignore [%raw "window._rtShouldConvert = 0"];
};

shouldConvert
}

};

0 comments on commit 87a0764

Please sign in to comment.