mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 17:45:22 +00:00
The pattern we were using for actions required actions to be defined in three places, an enum member containing the type string, an type definition and a function. This combines all three of these into one by using a helper function based on the ideas from [1]. [1]: https://phryneas.de/redux-typescript-no-discriminating-union
22 lines
583 B
TypeScript
22 lines
583 B
TypeScript
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2020-2022 The Pybricks Authors
|
|
|
|
import { createAction } from '../actions';
|
|
|
|
export type NotificationLevel = 'error' | 'warning' | 'info';
|
|
|
|
/**
|
|
* Action to add a notification to the list.
|
|
* @param level The severity level
|
|
* @param message The message to display to the user
|
|
* @param helpUrl An optional URL for more info
|
|
*/
|
|
export const add = createAction(
|
|
(level: NotificationLevel, message: string, helpUrl?: string) => ({
|
|
type: 'notification.action.add',
|
|
level,
|
|
message,
|
|
helpUrl,
|
|
}),
|
|
);
|