wangwangwar / daily-notes

Daily Notes
4 stars 0 forks source link

Refactor Coding-iOS with MVVM and FRP #31

Closed wangwangwar closed 7 years ago

wangwangwar commented 9 years ago

Coding-iOS is the official iOS client for Coding.net.

Recently I'm learning ReactiveCocoa and reading some related projects(AshFurrow/C-41, jspahrsummers/GroceryList). I'm totally impressed by FRP's grace and MVVM's modularity. I decide to do some projects to verify my shallow understanding. Y not Coding-iOS?


wangwangwar commented 9 years ago

Preface

Q: Y do U Refactor?

A: I want to make the API requesting cleaner and more graceful. I want to make code testable (now there is no test).

Q: How do U Refactor?

A: I will try to wrap the API requesting in RAC signal form. I will try to add a VIEW MODEL layer to make the code testable.

Q: Where do U start?

A: API requesting.

Q: Y choose RAC and MVVM?

A: Because I'm learning them - -. OK, fetching DATA from server, showing DATA on screen. Receiving CHANGING from human, syncing DATA back to server. As you can see, DATA and CHANGING is the core (Who's not - -). This is RAC's advantage: hacking DATA and responding to CHANGING. Data-driven APP handle data often. Data from MACHINE and from HUMAN are both random and sloppy, often. If we want to keep the APP robust, we must test with data, all kinds of data. MVVM add a View Model layer between the View/Controller and the Model, which make data handling easier and testable.


wangwangwar commented 9 years ago

API Requesting

Class CodingNetAPIClient wraps AFNetworking and provides the common requesting methods. Class Coding_NetAPIManager (WTF class naming?) use CodingNetAPIClient to do specific requests. It includes all API requesting methods.

Here I want to:

  1. Wrap the common requesting methods in RACSignal form (thanks CodaFi/AFNetworking-RACExtensions).
  2. Implement specific requests by chaining the "common" signals.

wangwangwar commented 9 years ago

Due to "Coding-iOS"'s brain-fuck "Vendor" library, I decide to do my very personal fork, which may conflicts with the official version. And I move the code from https://coding.net/u/wangwangwar/p/Coding-iOS/git to https://github.com/wangwangwar/Coding-iOS-Fork, just for using Github's fantastic issue and pull request manager!