Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ebsi-bblake committed Apr 19, 2023
1 parent 1b6fb5c commit cb4a3ae
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion content/1-reactivity/1-declare-state/mithril/Name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export default function Name() {
let name = "John";

return {
view: () => m("h1", name),
view: () => m("h1", `Hello ${name}`),
};
}
7 changes: 2 additions & 5 deletions content/1-reactivity/2-update-state/mithril/Name.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import m from "mithril";

export default function Name() {
let name = "John";
setTimeout(() => {
name = "Jane";
m.redraw();
}, 1000);
name = "Jane";
return {
view: () => m("h1", name),
view: () => m("h1", `Hello ${name}`),
};
}
7 changes: 2 additions & 5 deletions content/1-reactivity/3-computed-state/mithril/DoubleCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import m from "mithril";

export default function DoubleCount() {
let count = 10;
setTimeout(() => {
count = count * 2;
m.redraw();
});
let doubleCount = count * 2;
return {
view: () => m("div", count),
view: () => m("div", doubleCount),
};
}
2 changes: 1 addition & 1 deletion content/2-templating/3-loop/mithril/Colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Colors() {
view: () =>
m(
"ul",
colors.map((color) => m("li", { key: color }, color))
colors.map((color, idx) => m("li", { key: idx }, color))
),
};
}
2 changes: 1 addition & 1 deletion content/2-templating/4-event-click/mithril/Counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Counter() {
return {
view: () =>
m(
"",
"div",
m("p", `Counter: ${count}`),
m("button", { onclick: incrementCount }, "+1")
),
Expand Down
8 changes: 4 additions & 4 deletions content/2-templating/6-conditional/mithril/TrafficLight.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const TRAFFIC_LIGHTS = ["red", "orange", "green"];

export default function TrafficLight() {
let lightIndex = 0;
let light = () => TRAFFIC_LIGHTS[lightIndex];
let currentLight = () => TRAFFIC_LIGHTS[lightIndex];

const nextLight = () =>
lightIndex + 1 > TRAFFIC_LIGHTS.length - 1
? (lightIndex = 0)
: (lightIndex = lightIndex + 1);

const instructions = () => {
switch (light()) {
switch (currentLight()) {
case "red":
return "STOP";
case "orange":
Expand All @@ -24,9 +24,9 @@ export default function TrafficLight() {
return {
view: () =>
m(
"",
"div",
m("button", { onclick: nextLight }, "Next light"),
m("p", `Light is: ${light()}`),
m("p", `Light is: ${currentLight()}`),
m("p", "You must ", m("span", instructions()))
),
};
Expand Down
4 changes: 1 addition & 3 deletions content/3-lifecycle/1-on-mount/mithril/PageTitle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import m from "mithril";

export default function PageTitle() {
let pageTitle = document.title;

return {
view: () => m("p", `Page title: ${pageTitle}`),
view: () => m("p", `Page title: ${document.title}`),
};
}

0 comments on commit cb4a3ae

Please sign in to comment.