Skip to content

Commit

Permalink
feat: InMemoryWrapper 구현, 파일 재구화 (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarjsdn3 committed Jun 2, 2024
1 parent 6e390d1 commit 379dcdb
Show file tree
Hide file tree
Showing 80 changed files with 689 additions and 139 deletions.
1 change: 1 addition & 0 deletions 14th-team5-iOS/App/Sources/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extension AppDelegate: MessagingDelegate {

debugPrint("Firebase registration token: \(token)")

// TODO: - UseCase, APIWorker 삭제하기
let useCase = FCMUseCase(FCMRepository: MeAPIs.Worker())
useCase.executeSavingFCMToken(token: .init(fcmToken: token))
.asObservable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

public class CopyInvitationUrlActivity: UIActivity {
enum Activity {
private enum Activity {
static let activityTitle: String = "초대 링크 복사"
static let activitySymbol: String = "doc.on.doc"
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol ActivityGlobalStateType {
func hiddenInvitationUrlIndicatorView(_ hidden: Bool) -> Observable<Bool>
}

final public class ActivityGlobalState: BaseGlobalState, ActivityGlobalStateType {
final public class ActivityGlobalState: BaseService, ActivityGlobalStateType {
public var event: PublishSubject<ActivityEvent> = PublishSubject<ActivityEvent>()

public func didTapCopyInvitationUrlAction() -> Observable<Void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public protocol CalendarGlobalStateType {
func didTapCalendarInfoButton(_ sourceView: UIView) -> Observable<Void>
}

final public class CalendarGlobalState: BaseGlobalState, CalendarGlobalStateType {
final public class CalendarGlobalState: BaseService, CalendarGlobalStateType {
public var event: BehaviorSubject<CalendarEvent> = BehaviorSubject<CalendarEvent>(value: .none)

public func pushCalendarPostVC(_ date: Date) -> Observable<Date> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public protocol MainServiceType {
func refreshMain() -> Observable<Void>
}

final public class MainService: BaseGlobalState, MainServiceType {
final public class MainService: BaseService, MainServiceType {
public var event = PublishSubject<MainEvent>()

@discardableResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol PostGlobalStateType {
func missionContentText(_ content: String) -> Observable<String>
}

final public class PostGlobalState: BaseGlobalState, PostGlobalStateType {
final public class PostGlobalState: BaseService, PostGlobalStateType {
public var input: BehaviorSubject<(String, String)> = BehaviorSubject<(String, String)>(value: ("", ""))
public var event: PublishSubject<PostEvent> = PublishSubject<PostEvent>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public protocol ProfileFeedGlobalStateType {
func didReceiveMemberId(memberId: BibbiFeedType) -> Observable<BibbiFeedType>
}

public final class ProfileFeedGlobalState: BaseGlobalState, ProfileFeedGlobalStateType {
public final class ProfileFeedGlobalState: BaseService, ProfileFeedGlobalStateType {

public var event: PublishSubject<ProfileFeedEvent> = PublishSubject()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public protocol ProfileGlobalStateType {
func refreshFamilyMembers() -> Observable<Void>
}

final public class ProfileGlobalState: BaseGlobalState, ProfileGlobalStateType {
final public class ProfileGlobalState: BaseService, ProfileGlobalStateType {
public var event: PublishSubject<ProfileEvent> = PublishSubject<ProfileEvent>()

public func refreshFamilyMembers() -> Observable<Void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public protocol RealEmojiGlobalStateType {
}


public final class RealEmojiGlobalState: BaseGlobalState, RealEmojiGlobalStateType {
public final class RealEmojiGlobalState: BaseService, RealEmojiGlobalStateType {
public var event: PublishSubject<RealEmojiEvent> = PublishSubject<RealEmojiEvent>()

public func didTapRealEmojiEvent(indexPath row: Int) -> RxSwift.Observable<Int> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public protocol TimerGlobalStateType {
func setInTime() -> Observable<Void>
}

final public class TimerGlobalState: BaseGlobalState, TimerGlobalStateType {
final public class TimerGlobalState: BaseService, TimerGlobalStateType {
public var event: BehaviorSubject<TimerEvent> = BehaviorSubject(value: .inTime)

public func setNotTime() -> RxSwift.Observable<Void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public protocol ToastMessageGlobalStateType {
func clearLastSelectedDate()
}

final public class ToastMessageGlobalState: BaseGlobalState, ToastMessageGlobalStateType {
final public class ToastMessageGlobalState: BaseService, ToastMessageGlobalStateType {
public var lastSelectedDate: Date = .distantFuture
public var event: BehaviorSubject<ToastMessageEvent> = BehaviorSubject<ToastMessageEvent>(value: .showAllFamilyUploadedToastView(false))

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// InMemoryKey.swift
// Hello
//
// Created by 김건우 on 6/2/24.
//

import Foundation

extension InMemoryWrapper.Key {

static let member: Self = "member"

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
//
// InMemoryStore.swift
// Core
// Hello
//
// Created by 김건우 on 5/20/24.
// Created by 김건우 on 6/2/24.
//

import Foundation

import RxSwift
import RxRelay

public struct InMemoryStore<T>: ~Copyable {
public struct InMemoryStore<T> {

// MARK: - Typealias
public typealias Relay = BehaviorRelay<T?>

// MARK: - Properties
private var relay = BehaviorRelay<T?>(value: nil)
private var relay = Relay(value: nil)

// MARK: - Intializer
public init(
Expand All @@ -22,19 +25,13 @@ public struct InMemoryStore<T>: ~Copyable {
self.relay.accept(initalValue)
}

// MARK: - Deinitalizer

deinit { relay.accept(nil) }



// MARK: - Read

public func value() -> T? {
public var value: T? {
relay.value
}

public var stream: BehaviorRelay<T?> { relay }
public var stream: Relay { relay }


// MARK: - Update
Expand All @@ -46,3 +43,4 @@ public struct InMemoryStore<T>: ~Copyable {
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//
// InMemorySubscript.swift
// Hello
//
// Created by 김건우 on 6/2/24.
//

import Foundation

import RxSwift
import RxRelay


extension InMemoryWrapper {

func registerInt(_ value: Int?, forKey key: Key) {
register(value, forKey: key.rawValue)
}

func registerFloat(_ value: Float?, forKey key: Key) {
register(value, forKey: key.rawValue)
}

func registerDouble(_ value: Double?, forKey key: Key) {
register(value, forKey: key.rawValue)
}

func registerBool(_ value: Bool?, forKey key: Key) {
register(value, forKey: key.rawValue)
}

func registerObject<T>(_ value: T?, forKey key: Key) where T: Encodable {
register(value, forKey: key.rawValue)
}

func registerData(_ value: Data?, forKey key: Key) {
register(value, forKey: key.rawValue)
}

}


extension InMemoryWrapper {

subscript(key: Key) -> Int? {
get { integer(forKey: key.rawValue) }
set {
guard let value = newValue else { return }
set(value, forKey: key.rawValue)
}
}

subscript(key: Key) -> Float? {
get { float(forKey: key.rawValue) }
set {
guard let value = newValue else { return }
set(value, forKey: key.rawValue)
}
}

subscript(key: Key) -> Double? {
get { double(forKey: key.rawValue) }
set {
guard let value = newValue else { return }
set(value, forKey: key.rawValue)
}
}

subscript(key: Key) -> Bool? {
get { bool(forKey: key.rawValue) }
set {
guard let value = newValue else { return }
set(value, forKey: key.rawValue)
}
}

subscript(key: Key) -> String? {
get { string(forKey: key.rawValue) }
set {
guard let value = newValue else { return }
set(value, forKey: key.rawValue)
}
}

subscript<T>(key: Key) -> T? where T: Codable {
get { object(forKey: key.rawValue, of: T.self) }
set {
guard let value = newValue else { return }
set(value, forKey: key.rawValue)
}
}

}


extension InMemoryWrapper {

subscript<T>(stream key: Key) -> Observable<T>? {
return stream(forKey: key.rawValue)
}

subscript<T>(
stream key: Key,
of type: T.Type
) -> Observable<T>? where T: Decodable {
return stream(forKey: key.rawValue, of: type)
}

}


extension InMemoryWrapper {

func integer(forKey key: Key) -> Int? {
integer(forKey: key.rawValue)
}

func float(forKey key: Key) -> Float? {
float(forKey: key.rawValue)
}

func double(forKey key: Key) -> Double? {
double(forKey: key.rawValue)
}

func bool(forKey key: Key) -> Bool? {
bool(forKey: key.rawValue)
}

func object<T>(forKey key: Key, of type: T.Type) -> T? where T: Decodable {
object(forKey: key.rawValue, of: T.self)
}

}



extension InMemoryWrapper {

func remove(forKey key: Key) {
remove(forKey: key.rawValue)
}

}



extension InMemoryWrapper {

public struct Key: Hashable, RawRepresentable, ExpressibleByStringLiteral {

public var rawValue: String

public init(rawValue: String) {
self.rawValue = rawValue
}

public init(stringLiteral value: StringLiteralType) {
self.rawValue = value
}

}

}
Loading

0 comments on commit 379dcdb

Please sign in to comment.