Skip to content

Instantly share code, notes, and snippets.

@luomein
luomein / OpenAPIClientRequestReducer.swift
Created December 25, 2023 13:03
OpenAPIClientRequestReducer
import Foundation
import ComposableArchitecture
public protocol OpenAPIClientRequestProtocol:Equatable{
associatedtype Client
associatedtype Request
associatedtype Response : Equatable
var client : Client {get}
var request: Request {get}
static func fetchOpenAPI(clientRequest: Self)async throws->Response
@luomein
luomein / OpenAPIClientRequestTests.swift
Created December 25, 2023 12:46
OpenAPIClientRequestTests
import XCTest
import OpenAPIRuntime
import OpenAPIURLSession
import HTTPTypes
fileprivate protocol OpenAPIClientRequestProtocol:Equatable{
associatedtype Client
associatedtype Request
associatedtype Response : Equatable
var client : Client {get}
@luomein
luomein / SpotifyAuthorizationUrlTests.swift
Last active December 18, 2023 05:33
SpotifyAuthorizationUrlTests
import XCTest
final class SpotifyAuthorizationUrlTests: XCTestCase {
func fetchAuthorizationUrl(input: Sendable) async throws -> Sendable {
let authorizationUrl = AuthorizationUrl()
let parameter = input as! AuthorizationUrl.Parameter
let response = try await authorizationUrl.asyncPopupWebLogin(url: parameter.url
, callbackURLScheme: parameter.redirect_uri.scheme!, prefersEphemeralWebBrowserSession: parameter.prefersEphemeralWebBrowserSession)
let responseComponents = URLComponents(url: response, resolvingAgainstBaseURL: false)
@luomein
luomein / AuthorizationUrl.swift
Last active December 18, 2023 05:23
AuthorizationUrl
import Foundation
import AuthenticationServices
public class AuthorizationUrl: NSObject, ASWebAuthenticationPresentationContextProviding {
public struct Parameter: Equatable{
public let url: URL
public let redirect_uri: URL
public let prefersEphemeralWebBrowserSession:Bool
public let response_type: String
public init(url: URL, redirect_uri: URL, prefersEphemeralWebBrowserSession: Bool, response_type: String) {
@luomein
luomein / BasicTests.swift
Created December 18, 2023 04:34
BasicTests
import XCTest
import ComposableArchitecture
@MainActor
@available(macOS 13.0, *)
final class BasicTests: XCTestCase {
let debounceDuration : DispatchQueue.SchedulerTimeType.Stride = 0.1
let testQueue = DispatchQueue.test
typealias TestReducer = BaseAsyncCallReducer<Int,Int>
@luomein
luomein / BaseAsyncCallReducer.swift
Last active December 18, 2023 04:31
BaseAsyncCallReducer
import ComposableArchitecture
struct BaseAsyncCallReducer<RequestType:Equatable, ResponseType:Equatable>: Reducer{
@Dependency(\.mainQueue) var mainQueue
//@Dependency(\.asyncCallClient) var asyncCallClient
@Dependency(\.errorHandler) var errorHandler
var fetch: ( Sendable) async throws -> Sendable
//public init(){}
public init(fetch: @escaping (Sendable)async throws -> Sendable) {
self.fetch = fetch
@luomein
luomein / ExampleSwiftUIView.swift
Created October 21, 2023 09:25
ExampleSwiftUIView
import SwiftUI
import ComposableArchitecture
import WebKit
public extension Notification.Name {
static let FromWKCoordinatorNotification = Notification.Name("FromWKCoordinatorNotification")
static let ToWKCoordinatorNotification = Notification.Name("ToWKCoordinatorNotification")
}
public enum WKMessageHandlersEvent: String, CaseIterable{
case test
@luomein
luomein / NotificationReducerTests.swift
Last active October 24, 2023 15:55
NotificationReducerTests
import XCTest
import ComposableArchitecture
import WebKit
public extension Notification.Name {
static let FromWKCoordinatorNotification = Notification.Name("FromWKCoordinatorNotification")
static let ToWKCoordinatorNotification = Notification.Name("ToWKCoordinatorNotification")
}
@MainActor
@luomein
luomein / NotificationReducer.swift
Last active October 24, 2023 15:55
NotificationReducer
import ComposableArchitecture
import WebKit
public struct NotificationReducer<T:Equatable> : Reducer{
var notificationAsyncStream: @Sendable () -> AsyncStream<Notification>
var fromWKCoordinatorNotification : Notification.Name
var toWKCoordinatorNotification : Notification.Name
var coordinatorID : String
public init(fromWKCoordinatorNotification: Notification.Name, toWKCoordinatorNotification: Notification.Name, coordinatorID: String) {
self.fromWKCoordinatorNotification = fromWKCoordinatorNotification
@luomein
luomein / ExampleSwiftUIView.swift
Last active October 21, 2023 09:02
ExampleSwiftUIView
import SwiftUI
import WebKit
public extension Notification.Name {
static let FromWKCoordinatorNotification = Notification.Name("FromWKCoordinatorNotification")
static let ToWKCoordinatorNotification = Notification.Name("ToWKCoordinatorNotification")
}
public enum WKMessageHandlersEvent: String, CaseIterable{
case test
case DOMContentLoaded