Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit 7f20a83

Browse files
committed
make compiled javascript dependency-free
1 parent 3f547da commit 7f20a83

File tree

3 files changed

+106
-153
lines changed

3 files changed

+106
-153
lines changed

lib/js/src/index.js

Lines changed: 55 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ml

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,79 +12,60 @@ type windowDescription =
1212
; instance: int Js.Nullable.t }
1313
[@@bs.deriving abstract]
1414

15-
type windowDescriptor =
16-
| Title of string
17-
| ClassName of string
18-
| RegexpTitle of string
19-
| RegexpClassName of string
20-
| Last of bool
21-
| Active of bool
22-
| X of int
23-
| Y of int
24-
| W of int
25-
| H of int
26-
| Instance of int
27-
2815
let escaped s = s |. Js.String2.replaceByRe [%re "/;/g"] ";;"
2916

30-
let stringOfWindowDescriptor = function
31-
| Title title ->
32-
Some ("TITLE:" ^ escaped title)
33-
| ClassName className ->
34-
Some ("CLASS:" ^ escaped className)
35-
| RegexpTitle regexpTitle ->
36-
Some ("REGEXPTITLE:" ^ escaped regexpTitle)
37-
| RegexpClassName regexpClassName ->
38-
Some ("REGEXPCLASS:" ^ escaped regexpClassName)
39-
| Last last ->
40-
if last then Some "LAST" else None
41-
| Active active ->
42-
if active then Some "ACTIVE" else None
43-
| X x ->
44-
Some ("X:" ^ string_of_int x)
45-
| Y y ->
46-
Some ("Y:" ^ string_of_int y)
47-
| W w ->
48-
Some ("W:" ^ string_of_int w)
49-
| H h ->
50-
Some ("H:" ^ string_of_int h)
51-
| Instance instance ->
52-
Some ("INSTANCE:" ^ string_of_int instance)
17+
let addStringDescriptor acc key value =
18+
let value = Js.Nullable.toOption value in
19+
match value with
20+
| Some value ->
21+
ignore @@ Js.Array2.push acc (key ^ ":" ^ escaped value)
22+
| None ->
23+
()
5324

54-
let optionMap f = function Some x -> Some (f x) | None -> None
25+
let addIntegerDescriptor acc key value =
26+
let value = Js.Nullable.toOption value in
27+
match value with
28+
| Some value ->
29+
ignore @@ Js.Array2.push acc (key ^ ":" ^ string_of_int @@ value)
30+
| None ->
31+
()
5532

56-
let filterSome xs =
57-
xs |. Js.Array2.filter Js.Option.isSome |. Js.Array2.map Js.Option.getExn
33+
let addBooleanDescriptor acc key value =
34+
let value = Js.Nullable.toOption value in
35+
match value with
36+
| Some true ->
37+
ignore @@ Js.Array2.push acc key
38+
| Some false | None ->
39+
()
5840

59-
let splitDescription windowDescription =
60-
[| windowDescription |. titleGet |. Js.Nullable.toOption
61-
|> optionMap (fun title -> Title title)
62-
; windowDescription |. classNameGet |. Js.Nullable.toOption
63-
|> optionMap (fun className -> ClassName className)
64-
; windowDescription |. regexpTitleGet |. Js.Nullable.toOption
65-
|> optionMap (fun regexpTitle -> RegexpTitle regexpTitle)
66-
; windowDescription |. regexpClassNameGet |. Js.Nullable.toOption
67-
|> optionMap (fun regexpClassName -> RegexpClassName regexpClassName)
68-
; windowDescription |. lastGet |. Js.Nullable.toOption
69-
|> optionMap (fun last -> Last last)
70-
; windowDescription |. activeGet |. Js.Nullable.toOption
71-
|> optionMap (fun active -> Active active)
72-
; windowDescription |. xGet |. Js.Nullable.toOption
73-
|> optionMap (fun x -> X x)
74-
; windowDescription |. yGet |. Js.Nullable.toOption
75-
|> optionMap (fun y -> Y y)
76-
; windowDescription |. wGet |. Js.Nullable.toOption
77-
|> optionMap (fun w -> W w)
78-
; windowDescription |. hGet |. Js.Nullable.toOption
79-
|> optionMap (fun h -> H h)
80-
; windowDescription |. instanceGet |. Js.Nullable.toOption
81-
|> optionMap (fun instance -> Instance instance) |]
82-
|. filterSome
41+
let descriptorTagged ~title ~className ~regexpTitle ~regexpClassName ~last
42+
~active ~x ~y ~w ~h ~instance () =
43+
let descriptors = [||] in
44+
addStringDescriptor descriptors "TITLE" title ;
45+
addStringDescriptor descriptors "CLASS" className ;
46+
addStringDescriptor descriptors "REGEXPTITLE" regexpTitle ;
47+
addStringDescriptor descriptors "REGEXPCLASS" regexpClassName ;
48+
addIntegerDescriptor descriptors "INSTANCE" instance ;
49+
addBooleanDescriptor descriptors "ACTIVE" active ;
50+
addBooleanDescriptor descriptors "LAST" last ;
51+
addIntegerDescriptor descriptors "X" x ;
52+
addIntegerDescriptor descriptors "Y" y ;
53+
addIntegerDescriptor descriptors "W" w ;
54+
addIntegerDescriptor descriptors "H" h ;
55+
let body = descriptors |. Js.Array2.joinWith "; " in
56+
"[" |. Js.String2.concatMany [|body; "]"|]
8357

8458
let descriptor windowDescription =
85-
let descriptors = splitDescription windowDescription in
86-
"["
87-
^ ( descriptors
88-
|. Js.Array2.map stringOfWindowDescriptor
89-
|. filterSome |. Js.Array2.joinWith "; " )
90-
^ "]"
59+
let title = windowDescription |. titleGet in
60+
let className = windowDescription |. classNameGet in
61+
let regexpTitle = windowDescription |. regexpTitleGet in
62+
let regexpClassName = windowDescription |. regexpClassNameGet in
63+
let instance = windowDescription |. instanceGet in
64+
let active = windowDescription |. activeGet in
65+
let last = windowDescription |. lastGet in
66+
let x = windowDescription |. xGet in
67+
let y = windowDescription |. yGet in
68+
let w = windowDescription |. wGet in
69+
let h = windowDescription |. hGet in
70+
descriptorTagged ~title ~className ~regexpTitle ~regexpClassName ~instance
71+
~active ~last ~x ~y ~w ~h ()

0 commit comments

Comments
 (0)