Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state.copyWith not overriding properties #12

Closed
BrianMwas opened this issue Oct 7, 2020 · 2 comments
Closed

state.copyWith not overriding properties #12

BrianMwas opened this issue Oct 7, 2020 · 2 comments

Comments

@BrianMwas
Copy link

BrianMwas commented Oct 7, 2020

Hi I have been trying to find out the problem for a whole two days and I still haven't found what the problem is
When writing the property_form_bloc with initialNote the state does not update no matter what I do here's the code

`class PropertyFormBloc extends Bloc<PropertyFormEvent, PropertyFormState> {
final IPropertyFacade _propertyFacade;
PropertyFormBloc(this._propertyFacade) : super(PropertyFormState.initial());

@OverRide
Stream mapEventToState(
PropertyFormEvent event,
) async* {
yield* event.map(
initialized: (e) async* {
e.initialPropertyOption.fold(
() => state,
(initialProperty) => state.copyWith(
isEditing: true,
property: initialProperty
)
);
print("current state is now $state");
},
nameChanged: (e) async* {
print("name changed ${e.name}");
yield state.copyWith(
property: state.property.copyWith(name: PropertyName(e.name)),
saveFailureOrSuccessOption: none()
);
},
descriptionEvent: (e) async* {
yield state.copyWith(
property: state.property.copyWith(description: e.description),
saveFailureOrSuccessOption: none()
);
},
saved: (e) async* {
Either<ClassFailure, String> failureOrSuccess;

      yield state.copyWith(
          isSaving: true,
          saveFailureOrSuccessOption: none()
      );
      if(state.property.name.isValid() && state.property.description.length > 5) {
        failureOrSuccess = state.isEditing ?
          await _propertyFacade.updateProperty(state.property)
            : await _propertyFacade.createProperty(state.property);
      }

      yield state.copyWith(
        isSaving: false,
        showErrorMessages: true,
        saveFailureOrSuccessOption: optionOf(failureOrSuccess)
      );
    }
);

}
}`
Am I missing something? When I log out the initial property in this case it logs out the initialPropertyOption but is unable to update the state. Any answer is welcome

@djordje-maslic
Copy link

try adding the type of the stream PropertyFormState.
@OverRide
Stream < PropertyFormState > mapEventToState(
PropertyFormEvent event,
) async* {
yield* event.map(

@BrianMwas
Copy link
Author

Thanks I tried it and found out I had not added yield to the event. Thanks for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants