Comments (4)
@saravananmnm It depends on what these different usecases are used for. If a presenter has multiple usecases, and each usecase does something different, then you would want to use different methods to handle the events of every usecase.
So naturally you would need to declare multiple methods.
However, if all these usecases are somehow related and can be handled by 1 function (rare) then you could just use the same handler for all of them. If your usecases return data used in the home page, perhaps they can be combined into 1 usecase.
If you could provide more information, I can probably give you some pointers.
Thanks
from flutter_clean_architecture.
@ShadyBoukhary Thanks for your reply.
In android i have used mvp clean architecture previously.
So here i cannot achieve those like mvp pattern.Is there any solution for that.?
In Flutter i have used kiwi for dependency injunction, So can i use that same here.
Android usecase structure
`public abstract class UseCase<T, Params> {
private final ThreadExecutor mExecutor;
private final PostExecutor mPostExecutor;
private final CompositeDisposable mDisposable;
private AndroObserver<T> mObserver;
private PublishRelay<Long> mTrigger;
public UseCase(ThreadExecutor executor, PostExecutor postExecution) {
this.mExecutor = executor;
this.mPostExecutor = postExecution;
this.mDisposable = new CompositeDisposable();
this.mTrigger = PublishRelay.create();
}
/**
* Builds an {@link Observable} which will be used when executing the current {@link UseCase}.
*/
public abstract Observable<T> buildUseCaseObservable(Params params);
/**
* Executes the current use case.
*
* @param observer {@link DisposableObserver} which will be listening to the observable build
* by {@link #buildUseCaseObservable(Params)} ()} method.
* @param params Parameters (Optional) used to build/execute this use case.
*/
public void execute(AndroObserver<T> observer, Params params) {
mObserver = observer;
mDisposable.clear();
addDisposable(this.buildUseCaseObservable(params)
.subscribeOn(Schedulers.from(mExecutor))
.observeOn(mPostExecutor.getScheduler())
.doOnError(error -> {
if (error instanceof HttpException)
mObserver.onRetry("Something went wrong,Please try again.", error, mTrigger);
})
.retryWhen(errors -> errors.flatMap((Function<Throwable, ObservableSource<?>>) error -> {
if (error instanceof HttpException)
return mTrigger;
else
return Observable.error(error);
}))
.subscribeWith(observer));
}
/**
* Dispose from current {@link CompositeDisposable}.
*/
public void dispose() {
if (!mDisposable.isDisposed()) {
mDisposable.dispose();
}
}
/**
* Dispose from current {@link CompositeDisposable}.
*/
private void addDisposable(Disposable disposable) {
mDisposable.add(disposable);
}
public AndroObserver<T> getObserver() {
return mObserver;
}
public void setObserver(AndroObserver<T> observer) {
mObserver = observer;
}
}`
from flutter_clean_architecture.
Hey @saravananmnm, I'm not entirely sure what you're trying to achieve.
What is it that you can do in MVP that you're unable to do with this package? The UseCase structure in Android is very similar.
from flutter_clean_architecture.
Perhaps this is what you're trying to do @saravananmnm ?
Note that you can use the same undone and onerror for all usecases if they have the same behavior, just use the same callback. Have your observers use call the same undone and on error. You don't have to declare one for every usecase as long as they do the same thing.
from flutter_clean_architecture.
Related Issues (20)
- Cant add AppBar via ControlledWidgetBuilder.builder HOT 2
- One Controller for multiple pages HOT 1
- RefreshUI and setState HOT 1
- Question: Same controller in multiple widgets HOT 9
- Error when migrating from flutter_clean_architecture ^3.0.2 to ^5.0.0 HOT 1
- [Question] About initViewState() migration HOT 1
- [Question] How do I write test for the controller or presenter class? HOT 5
- If try add block isolate I have error HOT 1
- refreshUI() doesn't work with Shared Controller. HOT 1
- Can u update to support flutter_bloc >=7.2.0 HOT 2
- Unable to override `initState` on ViewState HOT 3
- How to avoid rebuild in components.
- Migrate to support 2.10.3 HOT 1
- Update to flutter 3.0 HOT 4
- integrating with Riverpod HOT 2
- I tried to make a 100% test coverage in example app but stuck in 98.3 HOT 1
- Getting this issues while app is build on ios ?
- Getting this error on ios build ?
- Add support to Dart 3 HOT 1
- Error: 'View' is imported from both
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 flutter_clean_architecture.