Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
hip4yes committed Jan 24, 2020
1 parent 6237c9b commit 57c5ce7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Aurum.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Aurum'
s.version = '0.5.0'
s.version = '1.0.0'
s.summary = 'Evolution of Amber architecture'

# This description is used to generate tags and improve search results.
Expand Down
31 changes: 18 additions & 13 deletions Aurum/Classes/AurumActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ public struct AurumLink{
let storyboard: String
let id: String

public init(storyboard: String, id: String) {
self.storyboard = storyboard
self.id = id
}

func instantiate() -> UIViewController{
return UIStoryboard(name: storyboard, bundle: nil).instantiateViewController(withIdentifier: id)
}
}

public enum AurumRouteType{
public enum AurumTransitionType{
var isEmbedding: Bool{
switch self {
case .embed(_), .embedFullscreen, .cleanEmbed(_), .cleanEmbedFullscreen: return true
Expand Down Expand Up @@ -70,43 +75,43 @@ public class AurumActor<Action: AurumAction, InputAction: AurumAction, OutputAct
self.outputReducer = outputReducer
}

public func act(_ action: Action){
public func reduce(_ action: Action){
reducer(action)
}

public func output(_ action: OutputAction){
outputReducer(action)
}

public func route(to toController: UIViewController, type: AurumRouteType = .show, animated: Bool = true){
switch type {
public func route(to toController: UIViewController, transition: AurumTransitionType = .show, animated: Bool = true){
switch transition {
case .present: rootController?.present(toController, animated: animated, completion: nil)
case .push: rootController?.navigationController?.push(toController, animated: animated)
case .show: rootController?.show(toController, animated: animated)
case .baseReplace: rootController?.replaceWith(toController, animation: .transitionFlipFromLeft)
case .replace(let animation): rootController?.replaceWith(toController, animation: animation)
case .embedFullscreen, .cleanEmbedFullscreen:
if type.isCleanEmbedding { controller?.view.unembedAll() }
if transition.isCleanEmbedding { controller?.view.unembedAll() }
if let vc = controller { toController.embedIn(view: vc.view, container: vc) }
case .embed(let view), .cleanEmbed(let view):
if type.isCleanEmbedding { view.unembedAll() }
if transition.isCleanEmbedding { view.unembedAll() }
if let vc = controller { toController.embedIn(view: view, container: vc) }
}
}

public func route(link: AurumLink, type: AurumRouteType = .show, animated: Bool = true){
route(to: link.instantiate(), type: type, animated: animated)
public func route(link: AurumLink, transition: AurumTransitionType = .show, animated: Bool = true){
route(to: link.instantiate(), transition: transition, animated: animated)
}

@discardableResult public func route<Module: AurumModuleConfigurator>(module: Module.Type, data: Module.RequiredData, type: AurumRouteType = .show, animated: Bool = true, outputListener: ((Module.OutputAction) -> Void)? = nil) -> AurumModuleData<Module.InputAction>{
@discardableResult public func route<Module: AurumModuleConfigurator>(module: Module.Type, data: Module.RequiredData, transition: AurumTransitionType = .show, animated: Bool = true, outputListener: ((Module.OutputAction) -> Void)? = nil) -> AurumModuleData<Module.InputAction>{
let config = Module()
let data = config.create(data: data, rootController: type.isEmbedding ? rootController : nil, outputListener: outputListener)
route(to: data.controller, type: type, animated: animated)
let data = config.create(data: data, rootController: transition.isEmbedding ? rootController : nil, outputListener: outputListener)
route(to: data.controller, transition: transition, animated: animated)
return data
}

@discardableResult public func route<Module: AurumModuleConfigurator>(module: Module.Type, type: AurumRouteType = .show, animated: Bool = true, outputListener: ((Module.OutputAction) -> Void)? = nil) -> AurumModuleData<Module.InputAction> where Module.RequiredData == Void{
return route(module: module, data: (), type: type, animated: animated, outputListener: outputListener)
@discardableResult public func route<Module: AurumModuleConfigurator>(module: Module.Type, transition: AurumTransitionType = .show, animated: Bool = true, outputListener: ((Module.OutputAction) -> Void)? = nil) -> AurumModuleData<Module.InputAction> where Module.RequiredData == Void{
return route(module: module, data: (), transition: transition, animated: animated, outputListener: outputListener)
}

public func close(type: AurumRouteCloseType = .close, animated: Bool = true){
Expand Down
25 changes: 24 additions & 1 deletion Aurum/Classes/AurumController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

import UIKit
import Bond
import ReactiveKit

public protocol AurumStoreSetupable {
func set<S, A>(store: AurumStore<S, A>)
Expand All @@ -18,13 +20,34 @@ public protocol AurumController: class, AurumStoreSetupable {
var store: AurumStore<State, Action>! { get set }
}

extension AurumController{
public extension AurumController{
func set<S, A>(store: AurumStore<S, A>){
guard let s = store as? AurumStore<State, Action> else { fatalError("\(type(of: self)) failed to set store: expected <\(State.self), \(Action.self)> got <\(S.self), \(A.self)>") }
self.store = s
}
}

public extension AurumController{
var reduce: Subject<Action, Never> { return store.reducer }
var state: State { return store.state.value }

func field<T: Equatable>(_ extractor: @escaping (State) -> T) -> Signal<T, Never>{
return store.state.map(extractor).removeDuplicates()
}

func reduce(action: Action){
store.reduce(action: action)
}
}


infix operator ~>

public func ~><T: AurumController>(left: (T, UIButton), right: T.Action){
left.1.reactive.tap.replaceElements(with: right).bind(to: left.0.reduce)
}


private var UIView_Associated_Embeded: UInt8 = 0
extension UIView{
var embedded: [UIViewController]{
Expand Down
2 changes: 1 addition & 1 deletion Aurum/Classes/AurumMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public protocol AurumMiddlwareProvider {
func provide(forOutputAction action: OutputAction, state: State) -> [AurumMiddleware]
}

extension AurumMiddlwareProvider{
public extension AurumMiddlwareProvider{
func provide(forInputAction action: InputAction, state: State) -> [AurumMiddleware] { return [] }
func provide(forOutputAction action: OutputAction, state: State) -> [AurumMiddleware] { return [] }

Expand Down
9 changes: 4 additions & 5 deletions Aurum/Classes/AurumModuleConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ public protocol AurumModuleConfigurator {

init()

func initialize(data: RequiredData) -> (State, Reducer, MiddlewareProvider)
func controller(data: RequiredData) -> AurumLink

func initialize(data: RequiredData) -> (State, Reducer, MiddlewareProvider, AurumLink)

func didLoad<A: Actor>(actor: A)
}

public extension AurumModuleConfigurator{
func didLoad<A: Actor>(actor: A){ }

func create(data: RequiredData, rootController: UIViewController? = nil, outputListener: ((OutputAction) -> Void)? = nil) -> AurumModuleData<InputAction>{
let (state, reducer, provider) = initialize(data: data)
let vc = controller(data: data).instantiate()
let (state, reducer, provider, link) = initialize(data: data)
let vc = link.instantiate()
let store = AurumStorePerformer(state: state, reducer: reducer, provider: provider, rootController: rootController, controller: vc, outputListener: outputListener)

guard let vcs = vc as? AurumStoreSetupable else { fatalError("\(type(of: vc)) does not conforms to AurumController") }
Expand Down
3 changes: 2 additions & 1 deletion Aurum/Classes/AurumReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
public protocol AurumState {}

public protocol AurumAction {}
public class AurumEmptyAction: AurumAction{}

public protocol AurumReducer {
associatedtype State: AurumState
Expand All @@ -25,7 +26,7 @@ public protocol AurumReducer {
}

extension AurumReducer{
func wrapped() -> AurumReducerWrapper<State, Action, InputAction, OutputAction>{
public func wrapped() -> AurumReducerWrapper<State, Action, InputAction, OutputAction>{
return AurumReducerWrapper(reducer: self)
}
}
Expand Down
10 changes: 8 additions & 2 deletions Aurum/Classes/AurumStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ import UIKit
import ReactiveKit

public class AurumStore<State: AurumState, Action: AurumAction>{
let state: Property<State>

public let state: Property<State>
public let reducer = Subject<Action, Never>()

private let reduceAction: (Action) -> Void

init<InputAction: AurumAction, OutputAction: AurumAction>(performer: AurumStorePerformer<State, Action, InputAction, OutputAction>){
state = performer.state
reduceAction = performer.reduce
subscribe()
}

func reduce(action: Action){
reduceAction(action)
}

func subscribe(){
let _ = reducer.observeNext { [weak self] in self?.reduce(action: $0) }
}
}

public class AurumStorePerformer<State: AurumState, Action: AurumAction, InputAction: AurumAction, OutputAction: AurumAction>{
Expand Down

0 comments on commit 57c5ce7

Please sign in to comment.