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

Add doc on Redux vs Flutter BLoc #25

Open
behzodfaiziev opened this issue Sep 25, 2024 · 0 comments
Open

Add doc on Redux vs Flutter BLoc #25

behzodfaiziev opened this issue Sep 25, 2024 · 0 comments

Comments

@behzodfaiziev
Copy link
Owner

Redux vs Flutter Bloc Cheatsheet

Concept Redux Flutter Bloc Explanation
Store Single Store Multiple BLoCs (or Cubits) Redux uses a single store to hold the entire state of the app. Flutter Bloc allows multiple BLoCs, each handling a specific aspect of the state.
Action Actions (plain objects) Events (classes) In Redux, actions are plain objects dispatched to modify state. In Flutter Bloc, events are dispatched to trigger transitions to new states.
Reducer Reducer Functions Map<Event, State> Reducers take actions and the current state and return a new state. In Flutter Bloc, an event triggers state transitions.
State Store's State Bloc’s State Redux's store holds the entire application state. In Flutter Bloc, each Bloc manages its own piece of state.
Slice A section of state + reducers Bloc Cubit (or Bloc with map events) Redux slices break down the state into manageable sections. In Flutter Bloc, Cubits are simpler alternatives to Blocs, useful when events are not necessary.
Selector useSelector (from React-Redux) state.select (or listen to changes) A way to select a part of the state in React Redux. Flutter Bloc lets you listen to specific state changes using BlocListener or BlocBuilder.
Dispatch useDispatch (React Redux) Bloc.add(Event) or Cubit.method Redux dispatches actions using useDispatch, while in Flutter Bloc, you dispatch events with Bloc.add(). Cubits are more direct, calling methods to update state.
Middleware redux-thunk or redux-saga BlocObserver or EventTransformers Redux middleware allows async operations (API calls). Flutter Bloc has BlocObserver to track Bloc changes, and event transformers can transform incoming events.
Thunk (async actions) redux-thunk async* Streams Redux uses thunks for async logic. In Flutter Bloc, you use async* in the mapEventToState method to manage async calls and streams.
Provider Redux Provider (from React Redux) BlocProvider In both libraries, providers are used to expose a store (or Bloc) to a widget subtree.
@behzodfaiziev behzodfaiziev changed the title Add doc on Rev Add doc on Redux vs Flutter BLoc Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant