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

Debouncers #5

Closed
wants to merge 3 commits into from
Closed
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
27 changes: 10 additions & 17 deletions GoodReactor-Sample/GoodReactor-Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

/* Begin PBXBuildFile section */
0908A6462C91C0B10035A749 /* GoodCoordinator in Frameworks */ = {isa = PBXBuildFile; productRef = 0908A6452C91C0B10035A749 /* GoodCoordinator */; };
092188C22C8CD57900C6085A /* NewReactor in Frameworks */ = {isa = PBXBuildFile; productRef = 092188C12C8CD57900C6085A /* NewReactor */; };
099D61632C8211B500B86922 /* NewReactor in Frameworks */ = {isa = PBXBuildFile; productRef = 099D61622C8211B500B86922 /* NewReactor */; };
09545AF02CB6704900DC5A61 /* LegacyReactor in Frameworks */ = {isa = PBXBuildFile; productRef = 09545AEF2CB6704900DC5A61 /* LegacyReactor */; };
09545AF22CB6705100DC5A61 /* GoodReactor in Frameworks */ = {isa = PBXBuildFile; productRef = 09545AF12CB6705100DC5A61 /* GoodReactor */; };
099D61702C83447900B86922 /* GoodCoordinator in Frameworks */ = {isa = PBXBuildFile; productRef = 099D616F2C83447900B86922 /* GoodCoordinator */; };
099D61732C8472D300B86922 /* GoodNetworking in Frameworks */ = {isa = PBXBuildFile; productRef = 099D61722C8472D300B86922 /* GoodNetworking */; };
099D617F2C84A3CC00B86922 /* RandomNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099D617C2C84A3CC00B86922 /* RandomNumber.swift */; };
099D61802C84A3CC00B86922 /* RNGEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099D617D2C84A3CC00B86922 /* RNGEndpoint.swift */; };
5D4A9750299CCA4800DFAEAE /* GoodReactor in Frameworks */ = {isa = PBXBuildFile; productRef = 5D4A974F299CCA4800DFAEAE /* GoodReactor */; };
EA51F944299424A900B14A7C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA51F943299424A900B14A7C /* AppDelegate.swift */; };
EA51F94F299424AA00B14A7C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EA51F94E299424AA00B14A7C /* Assets.xcassets */; };
EA51F952299424AA00B14A7C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA51F950299424AA00B14A7C /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -73,8 +72,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
09545AF22CB6705100DC5A61 /* GoodReactor in Frameworks */,
0908A6462C91C0B10035A749 /* GoodCoordinator in Frameworks */,
092188C22C8CD57900C6085A /* NewReactor in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -83,9 +82,8 @@
buildActionMask = 2147483647;
files = (
099D61702C83447900B86922 /* GoodCoordinator in Frameworks */,
099D61632C8211B500B86922 /* NewReactor in Frameworks */,
5D4A9750299CCA4800DFAEAE /* GoodReactor in Frameworks */,
099D61732C8472D300B86922 /* GoodNetworking in Frameworks */,
09545AF02CB6704900DC5A61 /* LegacyReactor in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -280,8 +278,8 @@
);
name = "goodreactor-swiftui-sample";
packageProductDependencies = (
092188C12C8CD57900C6085A /* NewReactor */,
0908A6452C91C0B10035A749 /* GoodCoordinator */,
09545AF12CB6705100DC5A61 /* GoodReactor */,
);
productName = "goodreactor-swiftui-sample";
productReference = 092188B02C8CD2A100C6085A /* goodreactor-swiftui-sample.app */;
Expand All @@ -301,10 +299,9 @@
);
name = "GoodReactor-Sample";
packageProductDependencies = (
5D4A974F299CCA4800DFAEAE /* GoodReactor */,
099D61622C8211B500B86922 /* NewReactor */,
099D616F2C83447900B86922 /* GoodCoordinator */,
099D61722C8472D300B86922 /* GoodNetworking */,
09545AEF2CB6704900DC5A61 /* LegacyReactor */,
);
productName = "GoodReactor-Sample";
productReference = EA51F940299424A900B14A7C /* GoodReactor-Sample.app */;
Expand Down Expand Up @@ -707,13 +704,13 @@
isa = XCSwiftPackageProductDependency;
productName = GoodCoordinator;
};
092188C12C8CD57900C6085A /* NewReactor */ = {
09545AEF2CB6704900DC5A61 /* LegacyReactor */ = {
isa = XCSwiftPackageProductDependency;
productName = NewReactor;
productName = LegacyReactor;
};
099D61622C8211B500B86922 /* NewReactor */ = {
09545AF12CB6705100DC5A61 /* GoodReactor */ = {
isa = XCSwiftPackageProductDependency;
productName = NewReactor;
productName = GoodReactor;
};
099D616F2C83447900B86922 /* GoodCoordinator */ = {
isa = XCSwiftPackageProductDependency;
Expand All @@ -723,10 +720,6 @@
isa = XCSwiftPackageProductDependency;
productName = GoodNetworking;
};
5D4A974F299CCA4800DFAEAE /* GoodReactor */ = {
isa = XCSwiftPackageProductDependency;
productName = GoodReactor;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = EA51F938299424A900B14A7C /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"originHash" : "29f6f72823407f70983528a7c3a0a061ad6f1aa0c17e358f4623a31f0b714680",
"originHash" : "e66c8117d9b42237263b4de46edc4aa97b6cdad073c429d74b862601ff05bbc5",
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
"version" : "5.9.1"
"revision" : "e16d3481f5ed35f0472cb93350085853d754913f",
"version" : "5.10.1"
}
},
{
Expand All @@ -19,6 +19,15 @@
"version" : "4.3.0"
}
},
{
"identity" : "chronometer",
"kind" : "remoteSourceControl",
"location" : "https://github.com/KittyMac/Chronometer.git",
"state" : {
"revision" : "d21b89e5cb5929b5175bdb3ad710a52cbf497eaa",
"version" : "0.1.12"
}
},
{
"identity" : "combineext",
"kind" : "remoteSourceControl",
Expand All @@ -33,8 +42,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/GoodRequest/GoodLogger.git",
"state" : {
"revision" : "4c5761a062fd2a98c9b81078a029a14b67ccab2a",
"version" : "1.1.0"
"revision" : "8203802fcff9163a309bd5edd44cc6f649404050",
"version" : "1.2.4"
}
},
{
"identity" : "hitch",
"kind" : "remoteSourceControl",
"location" : "https://github.com/KittyMac/Hitch.git",
"state" : {
"revision" : "d6c147a1d70992db39a141cb5bf9cf8fbb776250",
"version" : "0.4.148"
}
},
{
"identity" : "sextant",
"kind" : "remoteSourceControl",
"location" : "https://github.com/KittyMac/Sextant.git",
"state" : {
"revision" : "52a77d0bce0210cf9557faef7fd0adb9a6da02fb",
"version" : "0.4.31"
}
},
{
"identity" : "spanker",
"kind" : "remoteSourceControl",
"location" : "https://github.com/KittyMac/Spanker.git",
"state" : {
"revision" : "d4b439bf76a40fb45d86a24d13b9c26e7d630eee",
"version" : "0.2.49"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Combine
import Foundation
import GoodReactor
import LegacyReactor

final class AboutViewModel: GoodReactor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Combine
import UIKit
import NewReactor
import GoodReactor

final class HomeViewController: BaseViewController<HomeViewModel> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//

import GoodCoordinator
import NewReactor
import GoodReactor
import Observation
import SwiftUI

// TODO: Coordinator reactor macro for empty reactors
@Observable final class AppReactor: Reactor {

typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

enum Action {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import GoodCoordinator
import NewReactor
import GoodReactor
import SwiftUI

@main struct goodreactor_swiftui_sampleApp: App {
Expand All @@ -16,6 +16,7 @@ import SwiftUI
MainWindow()
}
}

}

@NavigationRoot struct MainWindow: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import GoodCoordinator
import NewReactor
import GoodReactor
import SwiftUI

struct ContentView: View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
//

import GoodCoordinator
import NewReactor
import GoodReactor
import Observation
import SwiftUI

@Observable final class ContentViewModel: Reactor {

typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

enum Action {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import GoodCoordinator
import SwiftUI
import NewReactor
import GoodReactor

struct DetailView: View {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//

import GoodCoordinator
import NewReactor
import GoodReactor
import Observation

@Observable final class DetailViewModel: Reactor {

typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

enum Action {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SwiftUI
import NewReactor
import GoodReactor

struct HomeView: View {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation
import GoodCoordinator
import NewReactor
import GoodReactor
import Observation

@Observable final class HomeViewModel: Reactor {

typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

enum Action {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SwiftUI
import NewReactor
import GoodReactor

struct LoginView: View {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation
import GoodCoordinator
import NewReactor
import GoodReactor
import Observation

@Observable final class LoginViewModel: Reactor {

typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

enum Action {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Filip Šašala on 24/09/2024.
//

import NewReactor
import GoodReactor
import GoodCoordinator
import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import Foundation
import GoodCoordinator
import NewReactor
import GoodReactor
import Observation

@Observable final class ProfileViewModel: Reactor {

typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

enum Action {

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func makeInitialState() -> State {
Finally in the `reduce` function you define how `state` changes, according to certain `event`s:

```swift
typealias Event = NewReactor.Event<Action, Mutation, Destination>
typealias Event = GoodReactor.Event<Action, Mutation, Destination>

func reduce(state: inout State, event: Event) {
switch event.kind {
Expand Down
12 changes: 12 additions & 0 deletions Sources/GoodReactor/Identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ public extension Identifier {
}

}

// MARK: - Code location identifier

public final class CodeLocationIdentifier: Identifier {

public let id: String

public init(_ file: StaticString = #file, _ line: UInt = #line, _ column: UInt = #column) {
self.id = "\(file):\(line):\(column)"
}

}
18 changes: 17 additions & 1 deletion Sources/GoodReactor/MapTables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,31 @@ internal enum MapTables {

typealias AnyReactor = AnyObject

// State of a reactor
static let state = WeakMapTable<AnyReactor, Any>()

// Initial state of a reactor
static let initialState = WeakMapTable<AnyReactor, Any>()
static let destinations = WeakMapTable<AnyReactor, Any?>()

// Number of currently running asynchronous tasks for an event of a reactor
static let runningEvents = WeakMapTable<AnyReactor, Set<EventIdentifier>>()

// Subscriptions of a reactor (new way)
static let subscriptions = WeakMapTable<AnyReactor, Set<AnyTask>>()

// Debouncers of a reactor
static let debouncers = WeakMapTable<AnyReactor, Dictionary<DebouncerIdentifier, Any>>()

// State stream cancellable (Combine)
static let stateStreams = WeakMapTable<AnyReactor, Any>()

// Event stream cancellable (Combine)
static let eventStreams = WeakMapTable<AnyReactor, Any>()

// Logger of a reactor
static let loggers = WeakMapTable<AnyReactor, GoodLogger>()

// Semaphore lock of an event (does not matter which reactor it's running on)
static let eventLocks = WeakMapTable<EventIdentifier, AsyncSemaphore>()

}
Loading