diff --git a/demo/src/Test3.re b/demo/src/Test3.re new file mode 100644 index 0000000..dd5a0d1 --- /dev/null +++ b/demo/src/Test3.re @@ -0,0 +1,9 @@ +React.useEffect2( + () => { + Document.addMouseDownEventListener(onClickHandler, document); + Some( + () => Document.removeMouseDownEventListener(onClickHandler, document), + ); + }, + (onClick, outsideContainer.React.current), +); diff --git a/src/Ppx.re b/src/Ppx.re index 7a79cd6..6a4d57a 100644 --- a/src/Ppx.re +++ b/src/Ppx.re @@ -7,6 +7,12 @@ let raiseWithLoc = (~loc, msg, variables) => let diff = (list1, list2) => List.filter(x => !List.mem(x, list2), list1); +let rec unique = lst => + switch (lst) { + | [] => [] + | [h, ...t] => [h, ...unique(List.filter(x => x != h, t))] + }; + let quotes = str => "'" ++ str ++ "'"; let getIdents = (expression: Parsetree.expression) => { @@ -136,6 +142,7 @@ let useEffectExpand = (e: Parsetree.expression) => let missingDependencies = result |> List.map(Longident.name) + |> unique |> List.map(quotes) |> String.concat(", ");