generated from rafaelesantos/swift-readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68a31e7
commit 2786d5e
Showing
18 changed files
with
304 additions
and
67 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
.swiftpm/xcode/xcshareddata/xcschemes/RefdsDesignPatterns.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1600" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "RefdsDesignPatterns" | ||
BuildableName = "RefdsDesignPatterns" | ||
BlueprintName = "RefdsDesignPatterns" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "RefdsDesignPatterns" | ||
BuildableName = "RefdsDesignPatterns" | ||
BlueprintName = "RefdsDesignPatterns" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
@attached(extension, conformances: RefdsReduxActionProtocol) | ||
public macro RefdsReduxAction() = #externalMacro(module: "RefdsReduxMacros", type: "RefdsReduxActionMacro") | ||
|
||
public protocol RefdsReduxActionProtocol: Sendable {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Foundation | ||
|
||
@attached(extension, conformances: RefdsReduxMiddlewareProtocol) | ||
public macro RefdsReduxMiddleware< | ||
State: RefdsReduxStateProtocol | ||
>() = #externalMacro( | ||
module: "RefdsReduxMacros", | ||
type: "RefdsReduxMiddlewareMacro" | ||
) | ||
|
||
public protocol RefdsReduxMiddlewareProtocol { | ||
associatedtype State: RefdsReduxStateProtocol | ||
|
||
func middleware( | ||
state: State, | ||
action: RefdsReduxActionProtocol | ||
) async -> AsyncStream<RefdsReduxActionProtocol> | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
@attached(extension, conformances: RefdsReduxReducerProtocol) | ||
public macro RefdsReduxReducer< | ||
State: RefdsReduxStateProtocol, | ||
Action: RefdsReduxActionProtocol | ||
>() = #externalMacro(module: "RefdsReduxMacros", type: "RefdsReduxReducerMacro") | ||
|
||
public protocol RefdsReduxReducerProtocol { | ||
associatedtype State: RefdsReduxStateProtocol | ||
associatedtype Action: RefdsReduxActionProtocol | ||
|
||
func reduce( | ||
state: State, | ||
action: Action | ||
) async -> State | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Foundation | ||
|
||
@attached(extension, conformances: RefdsReduxStateProtocol) | ||
public macro RefdsReduxState() = #externalMacro(module: "RefdsReduxMacros", type: "RefdsReduxStateMacro") | ||
|
||
public protocol RefdsReduxStateProtocol: Sendable, Equatable {} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
@attached(extension, conformances: RefdsReduxStoreProtocol) | ||
public macro RefdsReduxStore< | ||
State: RefdsReduxStateProtocol | ||
>() = #externalMacro( | ||
module: "RefdsReduxMacros", | ||
type: "RefdsReduxStoreMacro" | ||
) | ||
|
||
@MainActor | ||
public protocol RefdsReduxStoreProtocol: ObservableObject { | ||
associatedtype State: RefdsReduxStateProtocol | ||
|
||
var state: State { get set } | ||
var reducer: (State, RefdsReduxActionProtocol) async -> State { get } | ||
var middlewares: [(State, RefdsReduxActionProtocol) async -> AsyncStream<RefdsReduxActionProtocol>] { get } | ||
|
||
func dispatch(action: RefdsReduxActionProtocol) async | ||
} | ||
|
||
public extension RefdsReduxStoreProtocol { | ||
func dispatch(action: RefdsReduxActionProtocol) async { | ||
let middlewares = self.middlewares | ||
let stateReduced = await reducer(state, action) | ||
|
||
withAnimation(.easeInOut) { state = stateReduced } | ||
|
||
for middleware in middlewares { | ||
let actions = await middleware(state, action) | ||
|
||
for await action in actions { | ||
await dispatch(action: action) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
|
||
public struct RefdsReduxActionMacro: ExpressionMacro { | ||
public static func expansion( | ||
of node: some FreestandingMacroExpansionSyntax, | ||
in context: some MacroExpansionContext | ||
) -> ExprSyntax { | ||
guard let enumDecl = node.as(EnumDeclSyntax.self) else { | ||
fatalError("@RefdsReduxAction must be applied to an enum.") | ||
} | ||
let protocolConformance = """ | ||
extension \(enumDecl.name.text): RefdsReduxActionProtocol {} | ||
""" | ||
return ExprSyntax(stringLiteral: protocolConformance) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
|
||
@main | ||
struct RefdsReduxMacroPlugin: CompilerPlugin { | ||
let providingMacros: [Macro.Type] = [ | ||
RefdsReduxActionMacro.self, | ||
RefdsReduxStateMacro.self, | ||
RefdsReduxReducerMacro.self, | ||
RefdsReduxMiddlewareMacro.self, | ||
RefdsReduxStoreMacro.self | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
|
||
public struct RefdsReduxMiddlewareMacro: ExpressionMacro { | ||
public static func expansion( | ||
of node: some FreestandingMacroExpansionSyntax, | ||
in context: some MacroExpansionContext | ||
) -> ExprSyntax { | ||
guard let actorDecl = node.as(ActorDeclSyntax.self) else { | ||
fatalError("@RefdsReduxState must be applied to an actor.") | ||
} | ||
let arguments = node.arguments | ||
guard arguments.count == 1, | ||
let stateType = arguments.first?.expression.description else { | ||
fatalError("@RefdsReduxMiddleware must be applied with State type, e.g. @RefdsReduxMiddleware(State).") | ||
} | ||
|
||
let protocolConformance = """ | ||
extension \(actorDecl.name.text): RefdsReduxMiddlewareProtocol { | ||
typealias State = \(stateType) | ||
} | ||
""" | ||
|
||
return ExprSyntax(stringLiteral: protocolConformance) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
|
||
public struct RefdsReduxReducerMacro: ExpressionMacro { | ||
public static func expansion( | ||
of node: some FreestandingMacroExpansionSyntax, | ||
in context: some MacroExpansionContext | ||
) -> ExprSyntax { | ||
guard let actorDecl = node.as(ActorDeclSyntax.self) else { | ||
fatalError("@RefdsReduxState must be applied to an actor.") | ||
} | ||
let arguments = node.arguments | ||
guard arguments.count == 2, | ||
let stateType = arguments.first?.expression.description, | ||
let actionType = arguments.last?.expression.description else { | ||
fatalError("@RefdsReduxReducer must be applied with State and Action types, e.g. @RefdsReduxReducer(State, Action).") | ||
} | ||
|
||
let protocolConformance = """ | ||
extension \(actorDecl.name.text): RefdsReduxReducerProtocol { | ||
typealias State = \(stateType) | ||
typealias Action = \(actionType) | ||
} | ||
""" | ||
|
||
return ExprSyntax(stringLiteral: protocolConformance) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
|
||
public struct RefdsReduxStateMacro: ExpressionMacro { | ||
public static func expansion( | ||
of node: some FreestandingMacroExpansionSyntax, | ||
in context: some MacroExpansionContext | ||
) -> ExprSyntax { | ||
guard let structDecl = node.as(StructDeclSyntax.self) else { | ||
fatalError("@RefdsReduxState must be applied to an struct.") | ||
} | ||
let protocolConformance = """ | ||
extension \(structDecl.name.text): RefdsReduxStateProtocol {} | ||
""" | ||
return ExprSyntax(stringLiteral: protocolConformance) | ||
} | ||
} |
Oops, something went wrong.