google / flutter_flux

Implementation of the Flux framework for Flutter
https://flutter.io
Apache License 2.0
375 stars 36 forks source link

Created ActionWatcherMixin, which auto unsubscribe widget from actions when is it disposed. #45

Closed vinicioslc closed 5 years ago

vinicioslc commented 5 years ago

This corrects a common scenario like: When listening to an action on a page A that pushes the navigator to another page B, when page B overlaps page A the developer is obliged to unsubscribe from all actions in which he used the listen function, generating an ugly code, like spagheti . With this approach the developer only needs to use the following function within page A that elá will perform the automatic unsubscribe when executing the dispose.

//my widget definition...
  @override
  void initState() {
    listenToAction(action, (_) { }); // automatically cancel subscription on dispose page
  }
//...

im using a mixin in my project while this pull isn't aprooved...

vinicioslc commented 5 years ago

Closed due to missing automated tests.