moff / angular2-flash-messages

Angular 2 flash messages module
52 stars 21 forks source link

Identify message by ID #7

Closed coldiary closed 7 years ago

coldiary commented 7 years ago

Hi again

I saw that, on removal, messages are filtered by text. With this method, multiple messages having the same text will potentially be removed before the end of their timeout when the first one is firing. So I suggest to filter them by a unique property:

Added sequential id property to FlashMessage to distinguish them

  1. Added id property of type number in FlashMessageInterface
  2. Added a static nextId variable in FlashMessage to save the next id value
  3. Added the id property in FlashMessage and assigning it to the current next id value from nextId then increment the static var
  4. Changed the closure provided to filter by an arrow function checking message comparing id property instead of text property

Note: This implementation with a static class variable is chosen for simplicity. Some other choices would be possible as well.