5
5
6
6
-- 2.1.1
7
7
8
- -- HTML is shorthand for "virtual DOM node"
8
+ -- Filename conventions --
9
+ -- Although I prefer lisp's (kebab-case ...), in Elm you
10
+ -- MUST be `CamelCase`. Variables should also be `camelCase`.
11
+ -- : @ https://en.wikipedia.org/wiki/Camel_case
12
+ -- : @ https://elmprogramming.com/constant.html
13
+ -- : @ http://tinyurl.com/programming-cases
14
+ --
15
+ -- : 🚫 `src/photo-groove.elm` wrong naming convention
16
+ -- : I expect all files follow module naming convention:
17
+ --
18
+ -- | Module name | File Path |
19
+ -- |--------------|--------------------|
20
+ -- | Main | ./Main.elm |
21
+ -- | HomePage | ./HomePage |
22
+ -- | Http.Helpers | ./Http/Helpers.elm |
23
+
24
+
25
+ -- Documentation and comments --
26
+ --
27
+ -- Module declaration _must come before_ `module` statement.
28
+ -- Repeat! DO NOT put comments before `module` statement:
29
+ --
30
+ -- : @ https://package.elm-lang.org/help/documentation-format
31
+
32
+
33
+ -- Working with the Document Object Model (DOM)
34
+ -- HTML is shorthand for "virtual DOM node" ...
9
35
-- : We generally don't use `node` directly, but use the HTML elements
10
36
-- such as `img`, `button`, so on.
11
37
-- : The following two lines are equivalent:
@@ -17,6 +43,7 @@ node "img" [ src "logo.png" ] []
17
43
-- fall back on `node` only when no alternative is available.
18
44
19
45
-- Commas --
46
+ -- Commas first takes some getting used to, but ...
20
47
-- : 🚫 Beware of mistakes!
21
48
-- : It's best to have commas at the start of the line, as lines can be mistaken
22
49
-- for syntactically valid Elm code — but NOT the code you intended to write.
@@ -35,3 +62,40 @@ rules = [
35
62
]
36
63
37
64
-- Instead of 3 distinct lines.
65
+ -- : instead of calling `rule` 3 times, with one argument,
66
+ -- the second call to `rule` is receiving 3 arguments.
67
+
68
+ rules = [
69
+ rule " Do not ..."
70
+ rule " Do NOT" -- I'm missing a comma!
71
+ , rule " No eating ..."
72
+ ]
73
+
74
+ -- The above commas first is easier to check mistakes.
75
+
76
+
77
+ -- More on the DOM structure --
78
+ -- The PhotoGroove module will render a basic DOM
79
+ --
80
+ -- : The functions that create elements — in this case, div, h1, and img
81
+ -- take exactly _two arguments_ in all cases:
82
+ --
83
+ -- 1. A list of attributes (or an empty `[]` list)
84
+ h1 [] [ text " Photo Groove" ]
85
+ -- 2. A list of _child DOM nodes_ (or an empty `[]` list)
86
+ img [ src " 1.jpeg" ] []
87
+ -- : If an element has neither attributes nor children?
88
+ br [] []
89
+
90
+
91
+ -- Qualified -vs- unqualified style
92
+ --
93
+ -- `String.filter` (qualified style)
94
+ -- : Uses the module's name here and now.
95
+ --
96
+ -- `import HTML exposing (div, h1, img, text)` allows for:
97
+ -- : Using `div` instead of `Html.div`
98
+ -- (this is an unqualified style.)
99
+ --
100
+ -- We can use unqualified style when we _expose_ the module.
101
+ -- It imports the module, and exposes `Html.function`
0 commit comments