GithubHelp home page GithubHelp logo

Hi i am following your template based on MVVM, But i was confused in how to forward data from view to data layer. would you please explain with login example? about mvvmtemplate HOT 6 CLOSED

drjacky avatar drjacky commented on May 12, 2024
Hi i am following your template based on MVVM, But i was confused in how to forward data from view to data layer. would you please explain with login example?

from mvvmtemplate.

Comments (6)

Drjacky avatar Drjacky commented on May 12, 2024

Please check ProductsListViewModel. That _idsQuery is your username/password from UI which you have set it by:

fun getProductsList() {
        loading(true)
        _idsQuery.value = ""
    }

Then your usecase receive that emit here: getBeersListUseCase(GetBeersListParams(ids = it))
Send it to your repository:

override fun invoke(params: GetBeersListParams): Listing<RecyclerItem> =
        productsRepository.getBeersById(params.ids)

and it sends to the API.

And here you can handle success/error of login:

val ldBeersList: LiveData<PagedList<RecyclerItem>> = switchMap(result) {
        loading(false)
        it.data
    }
    private val errorResult: LiveData<Throwable> = switchMap(result) {
        loading(false)
        it.error
    }

from mvvmtemplate.

droidwithme avatar droidwithme commented on May 12, 2024

from mvvmtemplate.

Drjacky avatar Drjacky commented on May 12, 2024

You said:

data from view to data layer"

Anyway, by Mappers, you could convert your data objects to each other. Create your custom Mapper.

from mvvmtemplate.

droidwithme avatar droidwithme commented on May 12, 2024

from mvvmtemplate.

droidwithme avatar droidwithme commented on May 12, 2024

from mvvmtemplate.

Drjacky avatar Drjacky commented on May 12, 2024

@droidwithme Instead of injecting API into *RemoteDataSource and doing mapping there and injecting *RemoteDataSource into *RepositoryImpl,
Do this instead:
Inject API into *RepositoryImpl and do the mapping there. Like:

class BlahRepositoryImpl @Inject constructor(
    private val blahApi: BlahApi
) : BlahRepository {

    override fun getItems(): Single<RecyclerItem> =
        blahApi.getItems().map { it.toDomain() }

}

I'd suggest you read this article again: https://proandroiddev.com/mvvm-with-clean-architecture-c2c021e05c89

from mvvmtemplate.

Related Issues (14)

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.