Comments (9)
@QoLTech thanks for reporting this!
Can you please put together a super simple app that exhibits this behavior?
I'm unable to reproduce this with the following code:
import 'package:bloc/bloc.dart';
abstract class CounterEvent {}
class Increment extends CounterEvent {
@override
String toString() => 'Increment';
}
class Decrement extends CounterEvent {
@override
String toString() => 'Decrement';
}
class CounterBloc extends Bloc<CounterEvent, int> {
@override
int get initialState => 0;
@override
Stream<int> mapEventToState(int currentState, CounterEvent event) async* {
if (event is Increment) {
yield currentState + 1;
}
if (event is Decrement) {
yield currentState - 1;
}
}
}
class SimpleBlocDelegate implements BlocDelegate {
@override
void onTransition(Transition transition) {
print(transition.toString());
}
}
void main() {
BlocSupervisor().delegate = SimpleBlocDelegate();
final counterBloc = CounterBloc();
for (int i = 0; i < 100; i++) {
counterBloc.dispatch(Increment());
}
}
from bloc.
I've got my code that I'm currently working on here. It's slightly more complicated than a sample app, but I can easily reproduce the error.
After building and running, just hit connect and after connecting, you'll be on the messaging page. You'll have to use this to send messages. To reproduce, I just rapidly send messages with a single digit (1-9). When I do this, I see 1-9 printed to the console which is from the listener for messages and I only see an extra 9 which is from the Bloc mapEventToState.
Let me know if you need anything else.
from bloc.
@QoLTech I finally had a chance to take a look and the reason why this is happening is because you are overriding transform
in the MessageBloc
and debouncing. If you remove the transform
override it will work as you expect.
from bloc.
In addition, I noticed that you have your own bloc_builder
and bloc_provider
. I'm not sure if this is intentional but if you want you can add flutter_bloc
to your dependencies and you'll have access to BlocBuilder
and BlocProvider
without needed to copy the code into your own project.
from bloc.
@QoLTech I finally had a chance to take a look and the reason why this is happening is because you are overriding
transform
in theMessageBloc
and debouncing. If you remove thetransform
override it will work as you expect.
That's great, thank you. Could you explain or link me to an explanation of how debouncing works?
In addition, I noticed that you have your own
bloc_builder
andbloc_provider
. I'm not sure if this is intentional but if you want you can addflutter_bloc
to your dependencies and you'll have access toBlocBuilder
andBlocProvider
without needed to copy the code into your own project.
Yes, I didn't realize that package was also on pub. I will make sure to add it as a dependency, rather than copy it into my own projects.
from bloc.
@QoLTech you can learn about denounce here.
Let me know if you have any other questions. 👍
from bloc.
@QoLTech you can learn about denounce here.
Let me know if you have any other questions.
At first I thought the time had something to do with it, but couldn't figure out what exactly. Can I ask what the benefit of something like this is? If a button gets tapped in quick succession? If so, why do it this way rather than checking the dispatched events for equality?
from bloc.
@QoLTech it’s useful if you’re implementing something like a search and you don’t want to make a network request after every key press because it will put unnecessary load on the backend.
You can debounce with a duration of something like 500 milliseconds and events that are dispatched less than 500 milliseconds apart won’t be processed. This allows you to only hit your backend after a user has stopped typing.
from bloc.
@QoLTech it’s useful if you’re implementing something like a search and you don’t want to make a network request after every key press because it will put unnecessary load on the backend.
You can debounce with a duration of something like 500 milliseconds and events that are dispatched less than 500 milliseconds apart won’t be processed. This allows you to only hit your backend after a user has stopped typing.
That's great, thank you.
from bloc.
Related Issues (20)
- docs: I need help understanding Bloc-to-Bloc Communication HOT 2
- feat(evented_bloc): A new package for Blocs and Cubits with the ability to fire events... HOT 1
- discussion: Implementing Dynamic Bloc Switching HOT 4
- ReplayBloc function onTransition() handles event _Undo instead of user defined event HOT 2
- fix: In Flutter v3.16.4 stable the fromJson method stopped working HOT 1
- Flutter Bloc With Alert Dialogs throws an error HOT 4
- why my code will result in error? HOT 2
- BlocBuilder not getting called after creating new task, ListView still displays old data HOT 2
- question: bloc with many datasets HOT 26
- feat: Use with Freezed HOT 1
- BlocBuilder only build once and stop rebuild with subsequent emit HOT 6
- fix: hydrated bloc stopped persisting state after update (^9.1.3) HOT 6
- Cannot override EventHandler (Bug?) HOT 1
- fix: The "New Bloc/Cubit" option is not showing in VSCode Extensions HOT 2
- feate
- feat: why not fusion bloc_concurrency package into bloc HOT 2
- feat: BlocListener that trigger once but with return specific prop like BlocSelector HOT 3
- Help: Flutter Bloc Test: Unexpected State Change After Multiple Events HOT 6
- Help:add a event but state not change HOT 3
- TabBarView bug with Scrollable.ensureVisible and bloc HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bloc.