Skip to content

Commit

Permalink
Release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nazeehshoura committed Jun 20, 2017
1 parent afddd46 commit 2ed0767
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 73 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ All notable changes to this project will be documented in this file.

---

## [0.3.0](https://github.com/nazeehshoura/RxState/releases/tag/0.3.0)

#### Anomalies
## [0.5.0](https://github.com/nazeehshoura/RxState/releases/tag/0.5.0)

* Replaces `observe(Driver<CurrentStateLastAction>) to observe(StoreType) in `MiddlewareType`.
* Uses RxSwift 3.5.0
* Uses RxCocoa 3.5.0
* Renames `action` to `lastDispatchedaAtion`.
* Renames `action` to `lastDispatchedaAtion`.
* Defines `StoreState` as a type alias for `[SubstateType]`

## [0.2.1](https://github.com/nazeehshoura/RxState/releases/tag/0.2.1)
## [0.3.0](https://github.com/nazeehshoura/RxState/releases/tag/0.3.0)

#### Anomalies
* Replaces `observe(Driver<CurrentStateLastAction>)` with `observe(StoreType)` in `MiddlewareType`.

## [0.2.1](https://github.com/nazeehshoura/RxState/releases/tag/0.2.1)

* Renames `Middleware` to `MiddlewareType`.
2 changes: 1 addition & 1 deletion RxState.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "RxState"
s.version = "0.3.0"
s.version = "0.5.0"
s.summary = "RxSwift + Redux"

# This description is used to generate tags and improve search results.
Expand Down
12 changes: 6 additions & 6 deletions RxState.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -420,7 +420,7 @@
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -450,10 +450,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3;
DYLIB_CURRENT_VERSION = 4;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = RxState/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand All @@ -474,10 +474,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3;
DYLIB_CURRENT_VERSION = 4;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = RxState/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
Expand Down
4 changes: 2 additions & 2 deletions RxState/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.3.0</string>
<string>0.5.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
63 changes: 37 additions & 26 deletions RxState/RxState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@ public protocol SubstateType {}
3. Allows access to the application state and last dipached action via `currentStateLastAction` Driver (Useful for creating middlewere).
*/
public protocol StoreType {

/// Inisiate the store with a main reducer that the dispatch method will use to reduce incomming actions
init(mainReducer: @escaping MainReducer)

/**
The last dispatched action with the resulted state.
*/
var stateLastAction: Driver<StateLastAction> { get }

/**
A Hot Observables of `StoreState`.
A Driver of `StoreState`.
To add substates to `StoreState`, dispatch `Store.Action.register(subStates: [SubstateType])`.
*/
var state: Observable<StoreState> { get }

var state: Driver<StoreState> { get }
/**
A Hot Observables of the last dispatched action.
A Driver of the last dispatched action.
If the value is `nil`, it means that no Action has been dispatched yet.
*/
var lastDispatchedaAtion: Observable<ActionType?> { get }

var lastDispatchedaAtion: Driver<ActionType?> { get }
/**
Dispatches a action, causing the `state` to be updated.

Expand All @@ -53,37 +58,40 @@ public protocol StoreType {

*/
func register(middlewares: [MiddlewareType])

}


public class Store: StoreType {

fileprivate let mainReducer: MainReducer

required public init(mainReducer: @escaping MainReducer) {
self.mainReducer = mainReducer
}

public var state: Observable<[SubstateType]> {
return _state
.asObservable()
.share(replay: 1, scope: SubjectLifetimeScope.forever)
.catchErrorJustReturn([])

public var stateLastAction: Driver<StateLastAction> {
return Driver.zip(
state
, lastDispatchedaAtion
) { (state: [SubstateType], lastDispatchedaAtion: ActionType?) -> StateLastAction in
StateLastAction(state, lastDispatchedaAtion)
}
}

public var state: Driver<[SubstateType]> {
return _state.asDriver()
}

public var middlewares: [MiddlewareType] = []

private let _state: Variable<StoreState> = Variable(StoreState())

public var lastDispatchedaAtion: Observable<ActionType?> {
return _lastDispatchedaAtion
.asObservable()
.share(replay: 1, scope: SubjectLifetimeScope.forever)
.catchErrorJustReturn(nil)

public var lastDispatchedaAtion: Driver<ActionType?> {
return _lastDispatchedaAtion.asDriver()
}
private let _lastDispatchedaAtion: Variable<ActionType?> = Variable(nil)

public func dispatch(action: ActionType) {
if let storeAction = action as? Store.Action {
_state.value = Store.reduce(state: _state.value, sction: storeAction)
Expand All @@ -95,7 +103,7 @@ public class Store: StoreType {

public func register(middlewares: [MiddlewareType]) {
self.middlewares.append(contentsOf: middlewares)

for middleware in middlewares {
middleware.observe(store: self)
}
Expand All @@ -110,7 +118,7 @@ extension Store {
/// Removes all substates in the store's state.
case reset
}

public static func reduce(state: StoreState, sction: Store.Action) -> StoreState {
switch sction {
case let .add(states):
Expand Down Expand Up @@ -151,3 +159,6 @@ public typealias MainReducer = ((_ state: StoreState, _ action: ActionType) -> S
This reducer is used by the store's dispatch function. It should call the respective reducer basied on the Action type.
*/
public typealias StoreState = [SubstateType]

/// A tuple representing the current application state and the last dispatched action.
public typealias StateLastAction = (currentState: [SubstateType], lastAction: ActionType?)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ final class AddTaskTableViewCell: TableViewCell {

private func bindViewModelOutputs() {

viewModel.outputs.addTaskButtonActivityIndicatorIsAnimating
let outputs = viewModel.generateOutputs()

outputs.addTaskButtonActivityIndicatorIsAnimating
.drive(addTaskButton.rx.activityIndicatorIsAnimating)
.disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class TaskTableViewCell: TableViewCell {
.drive(toggleTaskStatusButton.rx.isEnabled)
.disposed(by: disposeBag)

viewModel.outputs
outputs
.toggleTaskStatusButtonActivityIndicatorIsAnimating
.drive(toggleTaskStatusButton.rx.activityIndicatorIsAnimating)
.disposed(by: disposeBag)
Expand Down
6 changes: 4 additions & 2 deletions RxStateExample/RxStateExample/Flow/macOS/TaskView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class TaskView: View {
}

private func bindViewModelOutputs(){
viewModel.outputs
let outputs = viewModel.generateOutputs()

outputs
.summary
.drive(SummaryTextField.rx.text)
.disposed(by: disposeBag)

viewModel.outputs
outputs
.toggleTaskStatusButtonIsSelected
.drive(toggleTaskStatusButton.rx.state)
.disposed(by: disposeBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol TaskViewViewModelType: ViewModelType {
// Going ☝️ to the store
func set(inputs: TaskViewViewModel.Inputs) -> Disposable
// Going 👇 from the store
var outputs: TaskViewViewModel.Outputs { get }
func generateOutputs() -> TaskViewViewModel.Outputs
}

struct TaskViewViewModel: TaskViewViewModelType {
Expand Down Expand Up @@ -67,7 +67,7 @@ struct TaskViewViewModel: TaskViewViewModelType {
let toggleTaskStatusButtonIsSelected: Driver<Int>
}

var outputs: TaskViewViewModel.Outputs {
func generateOutputs() -> TaskViewViewModel.Outputs {

let toggleTaskStatusTransformerInputs = ToggleTaskStatusTransformer.Inputs(store: self.store, taskId: taskId)
let toggleTaskStatusTransformerOutputs = ToggleTaskStatusTransformer.transtorm(inputs: toggleTaskStatusTransformerInputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ class TasksViewController: ViewController {
}

private func bindViewModelOutputs() {
viewModel.outputs.title
let outputs = viewModel.generateOutputs()

outputs.title
.drive(titleTextField.rx.text)
.disposed(by: disposeBag)

viewModel.outputs.reloadTasksTableViewSignal
outputs.reloadTasksTableViewSignal
.drive(onNext: {
self.tasksTableView.reloadData()
}, onCompleted: nil, onDisposed: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protocol TasksViewControllerViewModelType: ViewModelType, NSTableViewDataSource,
// Going ☝️ to the store
func set(inputs: TasksViewControllerViewModel.Inputs) -> Disposable
// Going 👇 from the store
var outputs: TasksViewControllerViewModel.Outputs { get }
func generateOutputs() -> TasksViewControllerViewModel.Outputs
}

class TasksViewControllerViewModel: NSObject, TasksViewControllerViewModelType {
Expand Down Expand Up @@ -64,7 +64,7 @@ class TasksViewControllerViewModel: NSObject, TasksViewControllerViewModelType {
let title: Driver<String>
}

var outputs: TasksViewControllerViewModel.Outputs {
func generateOutputs() -> TasksViewControllerViewModel.Outputs {
let reloadTasksTableViewSignal = tasks
.asDriver()
.distinctUntilChanged({ (lhsTasks: [Task], rhsTasks: [Task]) -> Bool in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class LoggingMiddleware: LoggingMiddlewareType {
var disposeBag = DisposeBag()

func observe(store: StoreType) {
store.currentStateLastAction
store.stateLastAction
.drive(
onNext: { (currentState: [SubstateType], lastAction: ActionType?) in
print("\n---------------------------------------------")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ extension Store {
extension StoreType {

/// A convenience variable to extract `Store.TasksState` from the application state
var presentableError: Observable<Error> {
var presentableError: Driver<Error> {
let presentableError = store.state
.flatMap { (states: [SubstateType]) -> Observable<Error> in
.flatMap { (states: [SubstateType]) -> Driver<Error> in

guard let errorStateManagerState = states
.first(where: { (state: SubstateType) -> Bool in
Expand All @@ -73,10 +73,10 @@ extension StoreType {

guard let presentableError = errorStateManagerState.presentableError
else {
return Observable.never()
return Driver.never()
}

return Observable.of(presentableError)
return Driver.of(presentableError)
}

return presentableError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ extension Store {
extension StoreType {

/// A convenience computed variable to extract `Store.FlowState` from the application state
var flowState: Observable<Store.FlowState> {
var flowState: Driver<Store.FlowState> {
let flowState = store.state
.flatMap { (states: [SubstateType]) -> Observable<Store.FlowState> in
.flatMap { (states: [SubstateType]) -> Driver<Store.FlowState> in
for state in states {
guard let value = state as? Store.FlowState else { continue }
return Observable<Store.FlowState>.just(value)
return Driver<Store.FlowState>.just(value)
}
fatalError("You need to register `Store.FlowState` first")
}
Expand All @@ -95,26 +95,26 @@ extension StoreType {
}

/// A convenience computed variable to extract `Store.FlowState.navigatableController` from the application state
var navigatableController: Observable<NavigatableController> {
let navigatableController: Observable<NavigatableController> = store.flowState
var navigatableController: Driver<NavigatableController> {
let navigatableController: Driver<NavigatableController> = store.flowState
.map { (state: Store.FlowState) -> NavigatableController in
return state.currentRouteNavigatableController
}
return navigatableController
}

/// A convenience computed variable to extract `Store.FlowState.originRoute` from the application state
var originRoute: Observable<Route?> {
let originRoute: Observable<Route?> = store.flowState
var originRoute: Driver<Route?> {
let originRoute: Driver<Route?> = store.flowState
.map { (state: Store.FlowState) -> Route? in
return state.currentRoute
}
return originRoute
}

/// A convenience computed variable to extract `Store.FlowState.originRoute` from the application state
var currentRoute: Observable<Route?> {
let currentRoute: Observable<Route?> = store.flowState
var currentRoute: Driver<Route?> {
let currentRoute: Driver<Route?> = store.flowState
.map { (state: Store.FlowState) -> Route? in
return state.currentRoute
}
Expand Down
Loading

0 comments on commit 2ed0767

Please sign in to comment.