attach method
Returns a new version of this pulse with updated context metadata.
Use this method to inject diagnostic information, security credentials, or timestamps into a pulse without altering its core payload.
When to use
- Tracing: Attaching a unique request ID to track a signal's lifecycle.
- Authorization: Injecting user permissions into a pulse before it reaches a protected receptor.
- Auditing: Adding a timestamp to mark when a specific processing stage was reached.
Example
final data = Pulse('Secure Data');
// Attach metadata fluently
final authenticatedPulse = data.attach({'user': 'admin', 'role': 'editor'});
print(authenticatedPulse.context); // {'user': 'admin', 'role': 'editor'}
Implementation
Pulse<P> attach(dynamic context) {
return evolve(context: context) as Pulse<P>;
}