Skip to content

Commit

Permalink
Update README and podspec.
Browse files Browse the repository at this point in the history
  • Loading branch information
lm2343635 committed Apr 17, 2019
1 parent 6c81ca5 commit 14df3cf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 7 deletions.
94 changes: 90 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
[![License](https://img.shields.io/cocoapods/l/RxController.svg?style=flat)](https://cocoapods.org/pods/RxController)
[![Platform](https://img.shields.io/cocoapods/p/RxController.svg?style=flat)](https://cocoapods.org/pods/RxController)

## Example
RxController is a library developing with MVVM-C based on **RxFlow** and **RxSwift**.
If you are not familiar with them, please learn these frameworks at first:

To run the example project, clone the repo, and run `pod install` from the Example directory first.
- RxSwift (https://github.com/ReactiveX/RxSwift)
- RxCocoa (https://github.com/ReactiveX/RxSwift)
- RxFlow (https://github.com/RxSwiftCommunity/RxFlow)

## Requirements
RxController provides the basic view controller and view model classes.
These classes make it easy to transfer data among the flows, the parent view models and the child view models.

## Installation
## Documentaion

RxController is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
Expand All @@ -20,6 +24,88 @@ it, simply add the following line to your Podfile:
pod 'RxController'
```

### Example

The example app helps you to understanding how to use RxController.
To run the example project, clone the repo, and run `pod install` from the Example directory first.

### Generic class of View Controller

RxController provides generic classes `RxViewController` and `RxChildViewController`.
With the genric classes, RxController avoids using an `Optional` or an `Implicit Unwrapping Option` type for the view model property in the view controller class.

In the demo app, we define the view model class by extending the RxViewModel class, and the view controller class by extending the RxViewController generic class.

```Swift
// View model class
class InfoViewModel: RxViewModel {

}

// View controller class
class InfoViewController: RxViewController<InfoViewModel> {

}
```

Then, we can initialize the `InfoViewController` with a safe way as the following.

```Swift
func navigate(to step: Step) -> FlowContributors {
guard let appStep = step as? AppStep else {
return .none
}
switch appStep {
case .start:
let infoViewController = InfoViewController(viewModel: InfoViewModel())
navigationController.pushViewController(infoViewController, animated: false)
return .viewController(infoViewController)
}
}
```

### Data Transportion among parent and child view models

In a standard MVVM-C architecture using RxFlow, view models exchange data via the flow classes using the `steps.accept()` method.
With `RxChildViewModel` and `RxChildViewController`, we can exchange data among parent and child view models without the flow class.

We define a event struct in the parent view model.

```Swift
struct InfoEvent {
static let name = RxControllerEventType(type: String.self)
static let number = RxControllerEventType(type: String.self)
}
```

Send a event from the parent view model.

```Swift
events.accept(InfoEvent.name.event("Alice"))
```

Send a event from the child view model.

```Swift
accept(event: accept(event: InfoEvent.name.event("Alice")
```

Receive a event in the parent view model.

```Swift
var name: Observable<String?> {
return events.value(of: InfoEvent.name)
}
```

Receive a event in the child view model.

```Swift
var name: Observable<String?> {
return parentEvents.value(of: InfoEvent.name)
}
```

## Author

lm2343635, lm2343635@126.com
Expand Down
8 changes: 5 additions & 3 deletions RxController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |s|
s.name = 'RxController'
s.version = '0.1'
s.summary = 'A short description of RxController.'
s.summary = 'A library for developing with MVVM-C based on RxFlow and RxSwift.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
Expand All @@ -18,14 +18,16 @@ Pod::Spec.new do |s|
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
TODO: Add long description of the pod here.
RxController is a library developing with MVVM-C based on RxFlow and RxSwift.
RxController provides the basic view controller and view model classes.
These classes make it easy to transfer data among the flows, the parent view models and the child view models.
DESC

s.homepage = 'https://github.com/lm2343635/RxController'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'lm2343635' => '[email protected]' }
s.source = { :git => 'https://github.com/lm2343635/RxController.git', :tag => s.version.to_s }
s.social_media_url = 'https://www.fczm.pe'
s.social_media_url = 'https://www.fczm.pw'

s.ios.deployment_target = '9.0'

Expand Down

0 comments on commit 14df3cf

Please sign in to comment.