Skip to content

Commit 12c5970

Browse files
committed
Add ProdDebug webcomponent
1 parent 89a34f0 commit 12c5970

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/Lib/ProdDebug.elm

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
{- This requires a port subscription by the host application.
1+
port module Lib.ProdDebug exposing (..)
22

3-
Something like:
3+
import Html exposing (Html, node)
4+
import Html.Attributes exposing (attribute)
45

5-
```javascript
6-
const app = Elm.HostApp.init({ flags });
76

8-
if (app.ports) {
9-
app.ports.debugLog?.subscribe((text) => {
10-
console.debug(text);
11-
});
12-
}
13-
```
14-
-}
7+
view : String -> List (Html msg) -> Html msg
8+
view debugMessage content =
9+
node "prod-debug" [ attribute "message" debugMessage ] content
1510

1611

17-
port module Lib.ProdDebug exposing (..)
12+
{-| This requires a port subscription by the host application.
1813
14+
Something like:
1915
16+
```javascript
17+
const app = Elm.HostApp.init({ flags });
18+
19+
if (app.ports) {
20+
app.ports.debugLog?.subscribe((text) => {
21+
console.debug(text);
22+
});
23+
}
24+
```
25+
26+
-}
2027
port debugLog : String -> Cmd msg

src/Lib/ProdDebug.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// <prod-debug message="debug message"></prod-debug>
2+
3+
class ProdDebug extends HTMLElement {
4+
constructor() {
5+
super();
6+
}
7+
8+
async connectedCallback() {
9+
const message = this.getAttribute("message");
10+
console.debug(message);
11+
}
12+
}
13+
14+
customElements.define("prod-debug", ProdDebug);

0 commit comments

Comments
 (0)