Skip to content

Commit

Permalink
Fix view state
Browse files Browse the repository at this point in the history
  • Loading branch information
joaolfp committed Jun 27, 2020
1 parent 81cb417 commit e5fdcde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 10 additions & 10 deletions Sources/ViewState/ViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class ViewState<T, E> : ObserverProtocol{

private var fetchSourceBehavior: () -> Void = {}

init() {
public init() {
observerRequest()
}

@discardableResult
func successObserver(_ success: @escaping (T) -> Void) -> ViewState {
public func successObserver(_ success: @escaping (T) -> Void) -> ViewState {

self.successBehavior.addObserver(self) { data in
success(data)
Expand All @@ -37,7 +37,7 @@ public class ViewState<T, E> : ObserverProtocol{
}

@discardableResult
func loadingObserver(_ loading: @escaping () -> Void) -> ViewState {
public func loadingObserver(_ loading: @escaping () -> Void) -> ViewState {
self.loadingBehavior.addObserver(self) { _ in
loading()
}
Expand All @@ -49,7 +49,7 @@ public class ViewState<T, E> : ObserverProtocol{
}

@discardableResult
func errorObserver(_ error: @escaping (E) -> Void) -> ViewState {
public func errorObserver(_ error: @escaping (E) -> Void) -> ViewState {
self.errorBehavior.addObserver(self) { aferror in
error(aferror)
}
Expand All @@ -60,7 +60,7 @@ public class ViewState<T, E> : ObserverProtocol{
return self
}

func fetchSource(_ request: @escaping () -> Void) {
public func fetchSource(_ request: @escaping () -> Void) {
self.fetchSourceBehavior = request
}

Expand All @@ -75,23 +75,23 @@ public class ViewState<T, E> : ObserverProtocol{
}
}

func success(data: T) {
public func success(data: T) {
self.successBehavior.value = data
}

func loading() {
public func loading() {
self.loadingBehavior.value = {}
}

func error(error: E) {
public func error(error: E) {
self.errorBehavior.value = error
}

func onValueChanged(_ value: Any?) {
public func onValueChanged(_ value: Any?) {
//empty
}

func verifyMakeRequest() {
public func verifyMakeRequest() {
if successObserved &&
loadingObserved &&
errorObserved {
Expand Down
1 change: 0 additions & 1 deletion Tests/ViewStateTests/ViewStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ final class ViewStateTests: XCTestCase {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(ViewState().text, "Hello, World!")
}

static var allTests = [
Expand Down

0 comments on commit e5fdcde

Please sign in to comment.