Skip to content

Commit b3bbe9d

Browse files
committed
Rename internal messages
1 parent adc35b0 commit b3bbe9d

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

src/grille_pain.gleam

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,40 @@ pub fn simple() {
4646

4747
fn update(model: Model, msg: Msg) {
4848
case msg {
49-
msg.RemoveToast(id) -> {
49+
msg.ToastHidDisplay(id) -> {
5050
let model = model.remove(model, id)
5151
let update = update_display(model)
5252
#(model, update)
5353
}
5454

55-
msg.StopToast(id) -> {
55+
msg.UserEnteredToast(id) -> {
5656
let model = model.stop(model, id)
5757
#(model, effect.none())
5858
}
5959

60-
msg.ExternalHide(uuid:) -> {
60+
msg.UserHidToast(uuid:) -> {
6161
case list.find(model.toasts, toast.by_uuid(_, uuid)) {
6262
Error(_) -> #(model, effect.none())
6363
Ok(toast) -> #(model, {
6464
use dispatch <- effect.from()
65-
dispatch(msg.HideToast(toast.id, toast.iteration))
65+
dispatch(msg.ToastTimedOut(toast.id, toast.iteration))
6666
})
6767
}
6868
}
6969

70-
msg.HideToast(id, iteration) -> {
70+
msg.ToastTimedOut(id, iteration) -> {
7171
case list.find(model.toasts, toast.by_iteration(_, id, iteration)) {
7272
Error(_) -> #(model, effect.none())
7373
Ok(toast) -> {
7474
let model = model.hide(model, toast.id)
75-
let to_remove = schedule(1000, msg.RemoveToast(id))
75+
let to_remove = schedule(1000, msg.ToastHidDisplay(id))
7676
let update = update_display(model)
7777
#(model, effect.batch([to_remove, update]))
7878
}
7979
}
8080
}
8181

82-
msg.ResumeToast(id) -> {
82+
msg.UserLeavedToast(id) -> {
8383
case list.find(model.toasts, toast.by_id(_, id)) {
8484
Error(_) -> #(model, effect.none())
8585
Ok(toast.Toast(sticky:, remaining:, iteration:, ..)) -> {
@@ -89,29 +89,29 @@ fn update(model: Model, msg: Msg) {
8989
}
9090
}
9191

92-
msg.NewToast(uuid:, message:, level:, timeout:, sticky:) -> {
92+
msg.UserAddedToast(uuid:, message:, level:, timeout:, sticky:) -> {
9393
model.add(uuid:, model:, message:, level:, timeout:, sticky:)
9494
|> pair.new(update_display(model))
9595
}
9696

9797
// Called after a requestAnimationFrame call.
9898
// Avoid to call an infinity of animation frames.
99-
msg.UpdateNextAnimationFrame(frame) -> {
99+
msg.LustreRequestedAnimationFrame(frame) -> {
100100
let next_frame = option.Some(frame)
101101
let model = Model(..model, next_frame:)
102102
#(model, effect.none())
103103
}
104104

105105
// Recompute positions of every toast, and schedule a management of
106106
// model to recompute next positions.
107-
msg.UpdateDisplay -> {
107+
msg.BrowserUpdatedToasts -> {
108108
let model = Model(..model, next_frame: option.None)
109109
let model = model.update_bottom_positions(model)
110110
#(model, update_toasts(model))
111111
}
112112

113113
// Compute the new state of toasts.
114-
msg.UpdateToasts -> {
114+
msg.LustreComputedToasts -> {
115115
let model = Model(..model, next_frame: option.None)
116116
case model.to_show {
117117
[] -> #(model, effect.none())
@@ -139,7 +139,7 @@ fn show(model: Model, id: Int, timeout: option.Option(Int), sticky: Bool) {
139139

140140
fn schedule_hide(sticky, timeout, id, iteration) {
141141
use <- bool.lazy_guard(when: sticky, return: effect.none)
142-
schedule(timeout, msg.HideToast(id, iteration))
142+
schedule(timeout, msg.ToastTimedOut(id, iteration))
143143
}
144144

145145
fn update_display(model: Model) {
@@ -148,9 +148,9 @@ fn update_display(model: Model) {
148148
option.None -> {
149149
use dispatch <- effect.from()
150150
dispatch({
151-
msg.UpdateNextAnimationFrame({
151+
msg.LustreRequestedAnimationFrame({
152152
use <- request_animation_frame()
153-
dispatch(msg.UpdateDisplay)
153+
dispatch(msg.BrowserUpdatedToasts)
154154
})
155155
})
156156
}
@@ -163,9 +163,9 @@ fn update_toasts(model: Model) {
163163
option.None -> {
164164
use dispatch <- effect.from()
165165
dispatch({
166-
msg.UpdateNextAnimationFrame({
166+
msg.LustreRequestedAnimationFrame({
167167
use <- request_animation_frame()
168-
dispatch(msg.UpdateToasts)
168+
dispatch(msg.LustreComputedToasts)
169169
})
170170
})
171171
}

src/grille_pain/internals/data/msg.gleam

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import grille_pain/internals/data/model
33
import grille_pain/toast/level.{type Level}
44

55
pub type Msg {
6-
ExternalHide(uuid: String)
7-
HideToast(id: Int, iteration: Int)
8-
NewToast(
6+
BrowserUpdatedToasts
7+
LustreComputedToasts
8+
LustreRequestedAnimationFrame(model.AnimationFrame)
9+
ToastHidDisplay(id: Int)
10+
ToastTimedOut(id: Int, iteration: Int)
11+
UserAddedToast(
912
uuid: String,
1013
message: String,
1114
level: Level,
1215
timeout: Option(Int),
1316
sticky: Bool,
1417
)
15-
RemoveToast(id: Int)
16-
ResumeToast(id: Int)
17-
StopToast(id: Int)
18-
UpdateDisplay
19-
UpdateToasts
20-
UpdateNextAnimationFrame(model.AnimationFrame)
18+
UserEnteredToast(id: Int)
19+
UserHidToast(uuid: String)
20+
UserLeavedToast(id: Int)
2121
}

src/grille_pain/internals/view.gleam

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ fn view_toast(toast: Toast) {
4343

4444
fn select_on_click_action(toast: Toast) {
4545
use <- bool.lazy_guard(when: toast.sticky, return: attribute.none)
46-
event.on_click(msg.HideToast(toast.id, toast.iteration))
46+
event.on_click(msg.ToastTimedOut(toast.id, toast.iteration))
4747
}
4848

4949
fn toast_container(toast: Toast, children: List(element.Element(Msg))) {
50-
let mouse_enter = event.on_mouse_enter(msg.StopToast(toast.id))
51-
let mouse_leave = event.on_mouse_leave(msg.ResumeToast(toast.id))
50+
let mouse_enter = event.on_mouse_enter(msg.UserEnteredToast(toast.id))
51+
let mouse_leave = event.on_mouse_leave(msg.UserLeavedToast(toast.id))
5252
[toast_colors(toast.level), toast_class()]
5353
|> list.map(css.compose)
5454
|> css.class

src/grille_pain/toast.gleam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn dispatch_toast(options: Options, message: String) {
5757
use dispatch <- effect_manager.call
5858
let Options(timeout:, level:, sticky:) = options
5959
let level = option.unwrap(level, level.Standard)
60-
msg.NewToast(uuid:, message:, level:, timeout:, sticky:)
60+
msg.UserAddedToast(uuid:, message:, level:, timeout:, sticky:)
6161
|> lustre.dispatch
6262
|> dispatch
6363
}
@@ -99,7 +99,7 @@ pub fn custom(options: Options, content: String) {
9999
/// Hide toast. Sticky toast can only be hidden using `hide`.
100100
pub fn hide(id: String) {
101101
use dispatch <- effect_manager.call
102-
msg.ExternalHide(id)
102+
msg.UserHidToast(id)
103103
|> lustre.dispatch
104104
|> dispatch
105105
}

0 commit comments

Comments
 (0)