Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Store and FeedbackLoop API. Rename it to Loop. #7

Merged
merged 6 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Example/MultiStoreExample/PaginationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ final class PaginationViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
viewModel.state.producer.startWithValues(contentView.render)
viewModel.store.context.startWithValues(contentView.render)
}
}

extension Movies {
final class ViewModel: Store<State, Event> {
final class ViewModel {
let store: Loop<State, Event>

init() {
super.init(
store = .init(
initial: Movies.State(),
reducer: Movies.reduce,
feedbacks: [Movies.feedback]
Expand Down
9 changes: 4 additions & 5 deletions Example/MultiStoreExample/TextInputViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class TextInputViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
viewModel.state.start()


textView.reactive.continuousTextValues
.take(duringLifetimeOf: self)
.observeValues { [viewModel] in viewModel.textDidChange($0) }
Expand All @@ -51,13 +50,13 @@ class TextInputViewController: UIViewController {
}

final class TextInputViewModel {
let state: FeedbackLoop<String, Event>
let state: Loop<String, Event>
private let (text, textObserver) = Signal<String, Never>.pipe()

init() {
self.state = FeedbackLoop<String, Event>(
self.state = Loop<String, Event>(
initial: "Lorem ipsum ",
reduce: TextInputViewModel.reduce,
reducer: TextInputViewModel.reduce,
feedbacks: [.custom { [text] (state, consumer) in
text.producer.map(Event.update).enqueue(to: consumer).start()
}]
Expand Down
8 changes: 5 additions & 3 deletions Example/MultiStoreExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
viewModel.state.producer.startWithValues(contentView.render)
viewModel.store.context.startWithValues(contentView.render)
}
}

extension Counter {
final class ViewModel: Store<State, Event> {
final class ViewModel {
let store: Loop<State, Event>

init() {
super.init(
store = .init(
initial: State(),
reducer: Counter.reduce,
feedbacks: []
Expand Down
12 changes: 9 additions & 3 deletions Example/SingleStoreExample/ColorPicker/ColorPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import UIKit
import Loop

final class ColorPickerViewController: ContainerViewController<ColorPickerView> {
private let store: Store<ColorPicker.State, ColorPicker.Event>
private let store: Loop<ColorPicker.State, ColorPicker.Event>

init(store: Store<ColorPicker.State, ColorPicker.Event>) {
init(store: Loop<ColorPicker.State, ColorPicker.Event>) {
self.store = store
super.init()
}
Expand All @@ -15,13 +15,18 @@ final class ColorPickerViewController: ContainerViewController<ColorPickerView>

override func viewDidLoad() {
super.viewDidLoad()
store.state.producer.startWithValues(contentView.render)

store.context.startWithValues(contentView.render)
contentView.didSelect.action = { [weak self] in
self?.navigationController?.popViewController(animated: true)
}
}
}

final class ColorPickerView: UIView, NibLoadable {
@IBOutlet var stackView: UIStackView!
let didTapButton = CommandWith<UIColor>()
let didSelect = Command()

func render(context: Context<ColorPicker.State, ColorPicker.Event>) {
zip(stackView.arrangedSubviews, context.colors).forEach { (view, color) in
Expand All @@ -34,5 +39,6 @@ final class ColorPickerView: UIView, NibLoadable {

@IBAction func didTapButton(sender: UIButton) {
didTapButton.action(sender.backgroundColor ?? .clear)
didSelect.action()
}
}
6 changes: 3 additions & 3 deletions Example/SingleStoreExample/Counter/CounterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import UIKit
import Loop

final class CounterViewController: ContainerViewController<CounterView> {
private let store: Store<Counter.State, Counter.Event>
private let store: Loop<Counter.State, Counter.Event>

init(store: Store<Counter.State, Counter.Event>) {
init(store: Loop<Counter.State, Counter.Event>) {
self.store = store
super.init()
}

override func viewDidLoad() {
super.viewDidLoad()
store.state.producer.startWithValues(contentView.render)
store.context.startWithValues(contentView.render)
}

required init?(coder: NSCoder) {
Expand Down
8 changes: 4 additions & 4 deletions Example/SingleStoreExample/Movies/Movies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ enum Movies {
}
}

static var feedback: FeedbackLoop<State, Event>.Feedback {
static var feedback: Loop<State, Event>.Feedback {
return .combine(
pagingFeedback(),
retryPagingFeedback()
Expand Down Expand Up @@ -146,8 +146,8 @@ enum Movies {
}
}

private static func pagingFeedback() -> FeedbackLoop<State, Event>.Feedback {
return FeedbackLoop<State, Event>.Feedback(skippingRepeated: { $0.nextPage }) { nextPage in
private static func pagingFeedback() -> Loop<State, Event>.Feedback {
return Loop<State, Event>.Feedback(skippingRepeated: { $0.nextPage }) { nextPage in
return URLSession.shared.fetchMovies(page: nextPage)
.observe(on: UIScheduler())
.map(Event.response)
Expand All @@ -157,7 +157,7 @@ enum Movies {
}
}

private static func retryPagingFeedback() -> FeedbackLoop<State, Event>.Feedback {
private static func retryPagingFeedback() -> Loop<State, Event>.Feedback {
return .init(skippingRepeated: { $0.retryPage }) { nextPage in
URLSession.shared.fetchMovies(page: nextPage)
.observe(on: UIScheduler())
Expand Down
10 changes: 5 additions & 5 deletions Example/SingleStoreExample/Movies/MoviesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import UIKit
import Loop

final class MoviesViewController: ContainerViewController<MoviesView> {
private let store: Store<Movies.State, Movies.Event>
private let store: Loop<Movies.State, Movies.Event>

init(store: Store<Movies.State, Movies.Event>) {
init(store: Loop<Movies.State, Movies.Event>) {
self.store = store
super.init()
}

override func viewDidLoad() {
super.viewDidLoad()
store.state.producer.startWithValues(contentView.render)
store.context.startWithValues(contentView.render)
contentView.didSelectItem.action = { [unowned self] movie in
let nc = self.navigationController!
let vc = ColorPickerViewController(
store: self.store.view(
value: \.colorPicker,
store: self.store.scoped(
to: \.colorPicker,
event: Movies.Event.picker
)
)
Expand Down
16 changes: 8 additions & 8 deletions Example/SingleStoreExample/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactiveSwift
import UIKit

final class RootViewController: UITabBarController {
private let store: Store<State, Event>
private let store: Loop<State, Event>

init() {
let appReducer: Reducer<State, Event> = combine(
Expand All @@ -19,14 +19,14 @@ final class RootViewController: UITabBarController {
)
)

let appFeedbacks: FeedbackLoop<State, Event>.Feedback = FeedbackLoop<State, Event>.Feedback.combine(
FeedbackLoop<State, Event>.Feedback.pullback(
let appFeedbacks: Loop<State, Event>.Feedback = Loop<State, Event>.Feedback.combine(
Loop<State, Event>.Feedback.pullback(
feedback: Movies.feedback,
value: \.movies,
event: Event.movies
)
)
store = Store(
store = Loop(
initial: State(),
reducer: appReducer,
feedbacks: [appFeedbacks]
Expand All @@ -41,14 +41,14 @@ final class RootViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let counterVC = CounterViewController(
store: store.view(
value: \.counter,
store: store.scoped(
to: \.counter,
event: Event.counter
)
)
let moviesVC = MoviesViewController(
store: store.view(
value: \.movies,
store: store.scoped(
to: \.movies,
event: Event.movies
)
)
Expand Down
Loading