-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscrollDirection.ts
More file actions
45 lines (37 loc) · 1.2 KB
/
scrollDirection.ts
File metadata and controls
45 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { RootStore, ScrollDirection } from "../../store";
import { Action } from "../action";
/**
* Arguments for the ScrollDirectionAction.
*/
export interface ScrollDirectionArgs {
to: ScrollDirection | "swap";
}
/**
* Action for setting the notefield scroll direction.
*/
export class ScrollDirectionAction implements Action {
args: ScrollDirectionArgs;
oldDirection!: ScrollDirection;
store: RootStore;
constructor(store: RootStore, args: ScrollDirectionArgs) {
this.args = args;
this.store = store;
}
run(): void {
const { to } = this.args;
const { data } = this.store.notefieldDisplay;
this.oldDirection = this.store.notefieldDisplay.data.scrollDirection;
if (to === "swap") {
if (data.scrollDirection === "up") {
this.store.notefieldDisplay.update({ scrollDirection: "down" });
} else {
this.store.notefieldDisplay.update({ scrollDirection: "up" });
}
} else {
this.store.notefieldDisplay.update({ scrollDirection: to });
}
}
undo(): void {
this.store.notefieldDisplay.update({ scrollDirection: this.oldDirection });
}
}