Bloc: When to use Equatable

Created on 14 Mar 2019  路  5Comments  路  Source: felangel/bloc

Hello 馃榿

  1. In which cases I don't need to Extends Equatable (or override the == operator as well as hashCode)?
    I use ever, but i don't know if i did it correct o simply i am adding more code :(

  2. If I have a State that Extends Equatable and this state have an other class like property, I need to extend Equatable also in this property?
    Thanks

class State extends Equatable{
  final Car car
  State(this.car): super([car]);
}

class Car{
  String type;
  String model;
  String color;
}

Thanks 馃

question

Most helpful comment

Hey @basketball-ico 馃憢

  1. You never need to extend Equatable. If you want to optimize your application to avoid rebuilding if the state doesn't change you can extend Equatable.
  2. Yes in order to accurately compare different instances of State you'd need to either have Car extend Equatable or have manually override == and hashCode.

Hope that helps! 馃憤

All 5 comments

Hey @basketball-ico 馃憢

  1. You never need to extend Equatable. If you want to optimize your application to avoid rebuilding if the state doesn't change you can extend Equatable.
  2. Yes in order to accurately compare different instances of State you'd need to either have Car extend Equatable or have manually override == and hashCode.

Hope that helps! 馃憤

Thanks I got it :D.

But i can't understand why you extends Equatable in theEvents of your examples.
I see that you compare the states if (currentState == nextState) return; but not the events.

Thanks

@basketball-ico great question! 馃挴

I extend Equatable in events as well because it makes it possible to do things like override transform in the bloc and manipulate the stream of events (using operators like debounce, distinct, etc..). Otherwise everything is technically a new/different Event.

Does that help?

Yeah, so for confirm :D, if I not need to override transform, not are any reason for extends Equatable in events. I am right?

Thanks ;D

@basketball-ico that's correct 馃憤

Was this page helpful?
0 / 5 - 0 ratings