Giter Club home page Giter Club logo

Comments (4)

ShadyBoukhary avatar ShadyBoukhary commented on May 18, 2024

@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.

saravananmnm avatar saravananmnm commented on May 18, 2024

@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.

ShadyBoukhary avatar ShadyBoukhary commented on May 18, 2024

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.

ShadyBoukhary avatar ShadyBoukhary commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.