event 1.1.3
event: ^1.1.3 copied to clipboard
Create lightweight custom Events, that allow interested subscribers to be notified that something has happened.
Changelog - Event #
1.1.3 - 2020-02-14 #
- BasicEventArgs renamed to StdEventArgs for clarity.
1.1.2 - 2020-02-09 #
- EventArgs changes
- Added
BasicEventArgsas a standardEventArgsderived type. It includes awhenOccurredfield that contains the date and time the Event wasbroadcast, as well as an optionaldescriptionfield. - Renamed
EventArgs1andEventArgs2toGenericEventArgs1andGenericEventArgs2respectively, to better indicate their purpose. Both are now derived fromBasicEventArgs, meaning that they havewhenOccurredand (optional)descriptionfields. - Improvements to documentation
- Added
- Minor improvements to Event documentation.
1.1.1 - 2020-02-03 #
- Add new method
unsubscribeAll, to unsubscribe all subscribers (handlers).
1.1.0 - 2020-01-29 #
Breaking Change
The function signature for an Event has been simplified. The sender argument has been removed, leaving only the need to provide an optional argument derived from type EventArgs.
The sender argument was previously intended to be used to provide the source of the Event, or the object in which the Event was declared, to a subscriber. This can be equally well done within an EventArg passed as an argument to a subscriber.
// Before
// subscribe to onValueChanged Event
myCounter.onValueChanged + (sender, args) => print('before');
// Now
// subscribe to onValueChanged Event
myCounter.onValueChanged + (args) => print('after');
Other Breaking Changes
- Renamed
addHandlerandremoveHandlermethods tosubscribeandunsubscriberespectively. - Renamed
raisemethods tobroadcast. - Method
broadcastWithSubjectremoved to reflect to removal ofsenderdescribed above. - The
countmethod has been renamed to `subscriberCount'
Other
- Two general purpose EventArg derived classes (
EventArgs1andEventArgs2) have been included, which offers a quick alternative to producing your own custom EventArgs class.
EventArgs1 supports one generic value, while EventArgs2 supports two. Example:-
// EventArgs1 (one value)
var e = Event<EventArgs1<String>>();
e.subscribe((args) => print(args.value));
e.broadcast(EventArgs1('hello'));
// prints hello
// EventArgs2 (two values)
var e = Event<EventArgs2<String, int>>();
e.subscribe((args) => print('${args.value1} - ${args.value2}'));
e.broadcast(EventArgs2('boom', 37));
// prints boom - 37
1.0.3 - 2020-01-22 #
- Added image of elevator example to README.
1.0.2 - 2020-01-22 #
- Updated reference to Flutter EventSubscriber in the README.
- Minor documentation improvements
1.0.1 - 2020-01-22 #
- Documentation improvements and corrections
1.0.0 - 2020-01-22 #
- Initial release