Skip to content

Commit

Permalink
Replaced Core functionality with equivalents in Js and Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
glennsl committed Feb 18, 2017
1 parent 4d12795 commit 639cc79
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 132 deletions.
2 changes: 1 addition & 1 deletion bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"ppx-flags": ["reason/reactjs_jsx_ppx.native"],
"bsc-flags": ["-w", "-40"],
"bs-dependencies": ["rehydrate", "reason-js"],
"bs-dependencies": ["rehydrate", "reason-js", "rebase"],
"sources": [{
"dir": "src/extension",
"subdirs": [
Expand Down
111 changes: 56 additions & 55 deletions docs/Popup.bundle.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "Adds Reason to the browser",
"repository": {
"type": "git",
"url": "https://github.com/rickyvetter/reason-tools.git"
"url": "https://github.com/reasonml/reason-tools.git"
},
"author": "rickyvetter",
"license": "MIT",
"homepage": "https://github.com/rickyvetter/reason-tools",
"homepage": "https://github.com/reasonml/reason-tools",
"keywords": [
"reason",
"reasonml",
Expand Down Expand Up @@ -44,19 +44,20 @@
"dependencies": {
"@opam-alpha/merlin": "^ 2.5.0",
"@opam-alpha/ocaml": "4.2.3",
"dependency-env": "https://github.com/reasonml/dependency-env.git",
"dependency-env": "reasonml/dependency-env",
"highlight.js": "^9.8.0",
"nopam": "https://github.com/reasonml/nopam.git",
"nopam": "reasonml/nopam",
"ocamlBetterErrors": "0.0.10",
"react": "^15.3.2",
"react-codemirror": "^0.2.6",
"react-copy-to-clipboard": "^4.2.3",
"react-dom": "^15.3.2",
"realpath": "*",
"reason": "https://github.com/facebook/reason.git",
"reason": "facebook/reason",
"rebase": "glennsl/rebase#v0.0.1",
"reason-js": "0.0.15",
"rebel": "https://github.com/reasonml/rebel.git",
"rehydrate": "https://github.com/reasonml/rehydrate.git"
"rebel": "reasonml/rebel",
"rehydrate": "reasonml/rehydrate"
},
"rebel": {
"targets": [
Expand All @@ -83,6 +84,6 @@
"generate-json-webpack-plugin": "^0.2.1",
"webpack": "^1.13.2",
"zip-webpack-plugin": "^0.2.0",
"bs-platform": "https://github.com/bloomberg/bucklescript.git"
"bs-platform": "bloomberg/bucklescript"
}
}
1 change: 1 addition & 0 deletions src/extension/Content.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
open Rebase;
open Core;
open Core.Dom;
open Common;
Expand Down
1 change: 1 addition & 0 deletions src/extension/Page.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
open Rebase;
open Core;
open Core.Dom;

Expand Down
7 changes: 4 additions & 3 deletions src/extension/Popup.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
open Rebase;
open Core;
open Core.Dom;

Expand All @@ -24,8 +25,8 @@ let getSelection () =>
maybeMaybeArray
|> Js.Null_undefined.to_opt
|> Option.map (fun maybeArray => Array.unsafe_get maybeArray 0)
|> Option.and_then (fun s => Str.isEmpty s ? None : Some s)
|> Option.map_or_else resolve reject
|> Option.andThen (fun s => Str.isEmpty s ? None : Some s)
|> Option.mapOrElse resolve reject
)
);

Expand All @@ -36,7 +37,7 @@ let getLatestInput () =>
(fun response =>
response##latestRefmtString
|> Js.Null.to_opt
|> Option.map_or_else resolve reject
|> Option.mapOrElse resolve reject
)
);

Expand Down
3 changes: 1 addition & 2 deletions src/extension/autoconverter/Common.re
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
open Core;
open Core.Dom;

let normalizeText text =>
text
|> Js.String.trim
|> Js.String.replaceByRe [%bs.re {|/[^\x00-\x7F]/g|}] " "
|> Js.String.replace (Str.fromCharCode 65533) "";
|> Js.String.replace (Js.String.fromCharCode 65533) "";

let getElementsByTagName maybeEl name =>
switch maybeEl {
Expand Down
2 changes: 1 addition & 1 deletion src/extension/autoconverter/Replace.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let escapeRe =

let replace this =>
Js.String.replaceByRe
(Re.make ("/\\b" ^ (escapeRe this) ^ "\\b/g"));
(Js.Re.fromString ("/\\b" ^ (escapeRe this) ^ "\\b/g"));

let replaceAll =
List.fold_left (fun out (this, that) => out |> replace this that);
Expand Down
2 changes: 1 addition & 1 deletion src/extension/autoconverter/UI.re
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let updateSyntaxSwapButton () => {
let ocamlLogoUrl = "url(" ^(Chrome.Extension.getURL ocamlLogo) ^ ")";

Style.setBackgroundImage style
(Js.to_bool (Str.includes (Style.backgroundImage style) reasonLogo) ? ocamlLogoUrl : reasonLogoUrl);
(Js.to_bool (Js.String.includes (Style.backgroundImage style) reasonLogo) ? ocamlLogoUrl : reasonLogoUrl);
};

let addSyntaxSwapButton swap => {
Expand Down
54 changes: 0 additions & 54 deletions src/extension/common/Core.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,6 @@ exception Unreachable;

let noop _ => ();

module Option = {
let unwrapUnsafely = fun
| Some v => v
| None => assert false;

let is_some = fun
| Some _ => true
| None => false;

let is_none = fun
| Some _ => false
| None => true;

let may f => fun
| Some v => f v
| None => ();

let or_ other => fun
| Some _ as self => self
| None => other;

let get_or other => fun
| Some v => v
| None => other;

let map f => fun
| Some v => Some (f v)
| None => None;

let map_or f other => fun
| Some v => f v
| None => other;

let map_or_else f g => fun
| Some v => f v
| None => g ();

let and_then f => fun
| Some v => f v
| None => None;
};

module MaybeArray = {
type t 'a;

Expand All @@ -57,18 +15,6 @@ module MaybeArray = {
|}];*/
};

module Str = {
external fromCharCode : int => string = "String.fromCharCode" [@@bs.val];
external fromCodePoint : int => string = "String.fromCodePoint" [@@bs.val];
external includes : string => string => Js.boolean = "includes" [@@bs.send];

let isEmpty s => String.length (String.trim s) == 0;
};

module Re = {
external make : string => Js.Re.t = "RegExp" [@@bs.new];
};

module Promise = {
type t 'a;

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

let iconStyle = {
"fontSize": "16vh"
};
Expand All @@ -12,7 +10,7 @@ let textStyle = {
let createElement ::show ::text="Text copied to clipboard" ::style=? children::_ () =>
(show ?
<div style=?style>
<div style=iconStyle> (ReactRe.stringToElement (Str.fromCodePoint 0x2398)) </div>
<div style=iconStyle> (ReactRe.stringToElement (Js.String.fromCodePoint 0x2398)) </div>
<div style=textStyle> (ReactRe.stringToElement text) </div>
</div> :
ReactRe.nullElement)
4 changes: 2 additions & 2 deletions src/extension/popup/components/ColumnTitle.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
open Core;
open Rebase;

let formatTitle name lang => name ^ " (" ^ lang ^ ")";

let createElement ::name ::lang children::_ () => {
let title = lang |> Option.map_or (formatTitle name) name;
let title = lang |> Option.mapOr (formatTitle name) name;

<span style=PopupStyles.contextTitle>
(ReactRe.stringToElement title)
Expand Down
5 changes: 3 additions & 2 deletions src/extension/popup/components/PopupWindow.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
open Rebase;
open Core;

module PopupWindow = {
Expand Down Expand Up @@ -69,8 +70,8 @@ module PopupWindow = {
<Editor value=props.outText lang=props.outLang readOnly=true />
<CopyConfirmation
style=PopupStyles.copyConfirmation
show=(Option.is_some state.copyConfirmation)
text=(Option.get_or "" state.copyConfirmation)
show=(Option.isSome state.copyConfirmation)
text=(Option.getOr "" state.copyConfirmation)
/>
</div>
</div>;
Expand Down

0 comments on commit 639cc79

Please sign in to comment.