Skip to content

feat(attr): add attribute change event system#9

Merged
SunYanbox merged 6 commits into
mainfrom
feature/attr-events
Jun 16, 2026
Merged

feat(attr): add attribute change event system#9
SunYanbox merged 6 commits into
mainfrom
feature/attr-events

Conversation

@SunYanbox

@SunYanbox SunYanbox commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Summary

Add an AttributeChanged event to Attr<TKey, TModId, TValue> that fires whenever a modifier mutation actually changes the computed attribute value.

Changes

Event System (d507ba2)

  • New AttributeChanged event — fires on every effective mutation (SetModifier, RemoveModifier, RemoveAllModifiers, Clear)
  • New AttrChangeType enumSetModifier, RemoveModifier, RemoveAll, Clear
  • New AttrChangedEventArgs<TKey, TValue> class — exposes Key, ChangeType, NewValue
  • Safe invocation — events fire outside per-key and global locks to prevent deadlocks when handlers call back into the attribute
  • Isolated subscribers — uses GetInvocationList() so one subscriber's exception does not block others
  • Cache-aware — cache is invalidated before the event fires, so GetValue inside handlers returns fresh data
  • No false events — setting a modifier to the same value remains a no-op and does not fire

Documentation Update (5697c0e)

  • Updated both English and Chinese READMEs to document the new APIs
  • Added event usage examples to Quick Start sections
  • Documented event safety guarantees and thread-safety implications

Testing

  • 312-line MSTest test suite (AttrEventTest.cs) covering all event scenarios
  • Tests verify correct invocation, isolation, no-op behavior, and lock safety
  • All existing tests continue to pass

Add AttributeChanged event that fires when a modifier mutation actually
changes the computed attribute value. Each subscriber is invoked
individually via GetInvocationList(), so one subscriber's exception
does not block others from receiving the event.

- New AttrChangeType enum (SetModifier, RemoveModifier, RemoveAll, Clear)
- New AttrChangedEventArgs<TKey, TValue> class
- Events fire outside per-key and global locks to prevent deadlocks
- Cache is invalidated before event firing so GetValue inside handlers
  returns fresh data
- Same-value SetModifier is still a no-op and does not fire events
…nges

- Add AttributeChanged event to API overview tables
- Document AttrChangeType enum and AttrChangedEventArgs class
- Add event usage example to Quick Start sections
- Document event safety guarantees (lock-free, isolated subscribers)
- Update thread safety section with event lock details
- Update features list to mention change event system
- Bilingual: English and Chinese READMEs aligned
@codecov-commenter

codecov-commenter commented Jun 16, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- Add AttrLoggingConfigurationTest: factory creation, env var toggling,
  BeginScope, log-level filtering, exception formatting, provider Dispose
- Add Attr constructor null-logger branch test (ArgumentNullException)
- Add ILogger dependency and constructor overloads to Attr
- Add AttrLoggingConfiguration with console/file logging via env vars
- Add event subscriber exception logging in RaiseAttributeChanged event
…Configuration

- Add Logging Configuration section documenting AttrLoggingConfiguration.CreateLoggerFactory()
- Document GAMEATTR_LOG_CONSOLE and GAMEATTR_LOG_FILE environment variables
- Add code example for configuring and passing ILogger to constructor
- Mention logging support in Features list
- Update 100% test coverage bullet to include event behavior
@SunYanbox

Copy link
Copy Markdown
Owner Author

Updates between 988cb96650796e

Three new commits were added to extend the event system with logging support and finalize documentation:

011d0d4 — feat(attr): add logging support to attribute change event system

  • Added Microsoft.Extensions.Logging dependency (Logging, Abstractions, Console)
  • Added AttrLoggingConfiguration — static helper that creates an ILoggerFactory from environment variables (GAMEATTR_LOG_CONSOLE, GAMEATTR_LOG_FILE)
  • Added a lightweight file logger provider writing to gameattr.log
  • Added Attr(ILogger<...>) constructor overload
  • Subscriber exceptions in RaiseAttributeChanged are now logged as warnings instead of swallowed silently

3adb185 — test: add comprehensive unit test coverage for logging configuration

  • 163-line MSTest suite (AttrLoggingConfigurationTest.cs) covering console output, file output, disabled console, and invalid environment variable values

650796e — docs(readme): add logging configuration documentation

  • Documented AttrLoggingConfiguration.CreateLoggerFactory() with environment variable reference table
  • Added code example for configuring and passing a logger to the constructor
  • Mentioned logging support in the Features list
  • Updated both English and Chinese READMEs

@SunYanbox SunYanbox merged commit 5f39850 into main Jun 16, 2026
4 checks passed
@SunYanbox SunYanbox deleted the feature/attr-events branch June 16, 2026 09:40
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