blob: bdce4d34f5d173889e3be7f8bdf82b84f7b81e93 [file] [log] [blame]
Philipp Schrader3d7dedc2024-03-16 16:27:25 -07001import {
2 ActionT,
3 ActionType,
4{% for action in ACTIONS %}
5 {{ action }}T,
6{% endfor %}
7} from '@org_frc971/scouting/webserver/requests/messages/submit_2024_actions_generated';
8
9export type ConcreteAction =
10{% for action in ACTIONS %}
11 {{ action }}T {% if not loop.last %} | {% endif %}
12{% endfor %};
13
14export class ActionHelper {
15 constructor(
16 private addAction: (actionType: ActionType, action: ConcreteAction) => void
17 ){}
18
19 {% for action in ACTIONS %}
20 // Calls `addAction` in entry.component.ts with the proper arguments. This
21 // also forces users to specify all the attributes in the `action` object.
22 public add{{ action}}(action: NonFunctionProperties<{{ action }}T>): void {
23 this.addAction(ActionType.{{ action }}, Object.assign(new {{ action }}T(), action));
24 }
25 {% endfor %}
26}
27
28type NonFunctionPropertyNames<T> = {
29 [K in keyof T]: T[K] extends Function ? never : K
30}[keyof T];
31
32type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;