Skip to content

feat(renderer): enhance notification system with customizable options - #216

Open
lhuans wants to merge 1 commit into
devfrom
lhs/renderer_notify
Open

feat(renderer): enhance notification system with customizable options#216
lhuans wants to merge 1 commit into
devfrom
lhs/renderer_notify

Conversation

@lhuans

@lhuans lhuans commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

渲染器 notify 去除组件库依赖,保持一致性

Summary by CodeRabbit

  • New Features
    • Added toast notifications for success, warning, error, and informational messages.
    • Notifications support titles, messages, automatic dismissal, hover-to-pause behavior, and manual closing.
    • Added support for custom notification handlers through renderer settings.
    • Exposed notification configuration types through the public API.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The renderer now supports typed notification settings, runtime settings accessors, configurable notification handlers, browser toast rendering with dismissal behavior, and console fallbacks. Notification-related types are also exposed through the public API.

Changes

Notification system

Layer / File(s) Summary
Notification settings and renderer wiring
projects/tiny-schema-renderer-ng/projects/renderer/src/renderer-settings.ts, projects/tiny-schema-renderer-ng/projects/renderer/src/renderer-main.ts, projects/tiny-schema-renderer-ng/projects/renderer/src/public-api.ts
Adds notification types, optional handlers, settings storage accessors, renderer initialization wiring, and public type exports.
Toast rendering and notification dispatch
projects/tiny-schema-renderer-ng/projects/renderer/src/parser/notify.ts
Implements configurable notification dispatch, DOM toast creation and styling, hover-aware auto-dismissal, and console fallback handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: yy-wow

Poem

I’m a rabbit with toast in my burrow tonight,
Typed little notices glowing just right.
Hover to pause, then fade from the view,
Custom handlers know what to do.
If browsers hide, logs still hop through!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: a renderer notification system upgrade with customizable options.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lhs/renderer_notify

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@projects/tiny-schema-renderer-ng/projects/renderer/src/renderer-main.ts`:
- Line 70: Remove the setRendererSettings call from the RendererMain constructor
or initialization path so component instantiation cannot overwrite module-level
currentSettings. Move renderer settings initialization to a single
application-level mechanism such as APP_INITIALIZER or a core singleton service;
if settings must differ per RendererMain instance, update notification dispatch
and parser utilities to receive instance-specific context instead of using the
global getter.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf4976fc-6c99-4661-8cee-10eef8914039

📥 Commits

Reviewing files that changed from the base of the PR and between 4c3e747 and f16fade.

📒 Files selected for processing (4)
  • projects/tiny-schema-renderer-ng/projects/renderer/src/parser/notify.ts
  • projects/tiny-schema-renderer-ng/projects/renderer/src/public-api.ts
  • projects/tiny-schema-renderer-ng/projects/renderer/src/renderer-main.ts
  • projects/tiny-schema-renderer-ng/projects/renderer/src/renderer-settings.ts

) {
this.cssScopeId = `data-schema-${Math.random().toString(36).slice(2, 8)}`;
this.contextService.setMaterials(this.rendererSettings?.materials ?? {});
setRendererSettings(this.rendererSettings);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Race condition on global renderer settings.

Updating a module-level singleton (currentSettings) from a component constructor causes a "last instance wins" race condition. If multiple RendererMain components are instantiated in the application (e.g., one with a custom notify handler and another without), the last instantiated component will immediately overwrite the settings for all instances globally.

If Notify requires access to custom handlers synchronously, consider initializing these global settings once (e.g., via Angular's APP_INITIALIZER or a core singleton service) instead of mutating global state on component instantiation. Alternatively, if instance-level notification configuration is necessary, the parsers and utilities triggering the notifications will need context-aware dispatching rather than relying on a static module-level getter.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@projects/tiny-schema-renderer-ng/projects/renderer/src/renderer-main.ts` at
line 70, Remove the setRendererSettings call from the RendererMain constructor
or initialization path so component instantiation cannot overwrite module-level
currentSettings. Move renderer settings initialization to a single
application-level mechanism such as APP_INITIALIZER or a core singleton service;
if settings must differ per RendererMain instance, update notification dispatch
and parser utilities to receive instance-specific context instead of using the
global getter.


export const RENDERER_SETTINGS = new InjectionToken<IRendererSettings>('RENDERER_SETTINGS');

let currentSettings: IRendererSettings = {};

@gimmyhehe gimmyhehe Jul 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

遗留:单例模式存在不同实例之间相互影响的问题,待优化方案

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants