The goal of this PR is to create a unified notification system that can be used across core, studio, and extensions.
Goals:
- Make it easy to create high quality notifications that provide helpful information in an easy to parse way.
- Should be a unified system for displaying both Studio notifications, and console notifications
- Should be unobtrusive, but unmissable
The way this is achieved is the following.
The notification API provides a structure that makes it easy to craft high-quality notifications:
notify.warning(
// Title
'Invalid path provided to object',
// Message. Can include markdown.
`The path in \`${fnName}("${unsanitisedPath}")\` was sanitized to \`"${sanitisedPath}"\`.\n\n` +
'Please replace the path with the sanitized one, otherwise it will likely break in the future.',
// Relevant docs
[
{
url: 'https://www.theatrejs.com/docs/latest/manual/objects#creating-sheet-objects',
title: 'Sheet Objects',
},
{
url: 'https://www.theatrejs.com/docs/latest/api/core#sheet.object',
title: 'API',
},
],
)
This will cause a notification to appear in studio's notification manager:
Notifications can freely include markdown paragraphs, code blocks, lists, etc.
Additionally, for warnings, a console log is also printed with the same message.
The collapsed notification manager shows the types of notifications currently in the list:
Notifications are by default deduplicated. A notification is only shown if there isn't already one displayed with the same content. This is useful since while we often don't care about cluttering the console, the studio UI is a different matter. Calling notify
should be idempotent in most cases. This way we don't have to worry about react rendering twice in a row, or calling notify
in a loop even.
You can opt out of this behavior through the last argument:
// this notification will be fired as many times as this code is run
notify.warning(
'My notification',
'Some message',
[],
// allow duplicates
true
)
The notification system is accessible across studio, extensions, and core.
When used in studio, the API is accessible through the following import:
import {notify} from '@theatre/studio/notify'
When used in core, the API is accessible through the following import:
import {notify} from '@theatre/shared/notify'
When used in extension code, the API is accessible through the following import:
import {notify} from '@theatre/studio'
Note, notifications fired in core will only be displayed if studio is loaded.