Skip to content

Instantly share code, notes, and snippets.

@ambas
Last active November 8, 2017 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambas/3b84a41e9af3d30faf46873458f8c7d1 to your computer and use it in GitHub Desktop.
Save ambas/3b84a41e9af3d30faf46873458f8c7d1 to your computer and use it in GitHub Desktop.
  • Start with Classes -> Modules -> Cart -> Section

  • In this folder you can see all section type that we have in cart. ( PS. LACartSection is legacy class)

  • I use IGListBindingSectionController for SectionController with this way it will automatically bind viewModel and cell for us.

  • in sectionController class, we have to implement some dataSource methods

    • First we need to return all viewModel for section
    • Each viewModel will map to cell so relationship for viewModel and cell will be 1 to 1. So its mean a viewModel will have a cell to show.
    • I use category to separate logic for build viewModels , for the final result we will return array of viewModel to IGListKit and all of this viewModel will be mapped to cell.
    • You can check category in folder Classes -> Modules -> Cart -> Categories
    • If you start reading code at sectionController you will see category of viewModel try to ask a list of viewModel from child viewModel . I use this way because I try to separate viewModel building logic. its kind of duplicate method but with this way the logic will be in specific place.
  • viewModel will be separated by type of business domain like LACartSellerViewModel, LACartLocationViewModel etc. please check Classes -> Modules -> Cart -> ViewModels folder

    • Each viewModel will hold branch of componentViewModel and we will always use component viewModel to map to cell
    • I designed these viewModel like hierarchy of viewModel. And we have only one way to talk with other module by talk to parent viewModel first. So its mean every action that made from child viewModel will be sent to parent viewModel first.
    • In component header you can see two parts of block call back, first for binding cell and second for talk with parent viewModel.

For sample project please check Cart Repo. In this repo I try to simulate our cart architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment