Swiftpack.co - Package - joeblau/composable-fast

ComposableFast

A Composable Architecture implementation of a fast.com speed test library.

Install

Add this to your Package.swift

.package(url: "https://github.com/joeblau/composable-fast", from: "0.1.0"),

Use

To understand how the composable architecture works, I higly recommend watching the four part series on Point Free

Setup

Import

import ComposableFast

Create Fast Manager id

struct FastManagerId: Hashable {}

Add Fast Manager to AppEnvironment

struct AppEnvironment {
    ...
    let fastManager: FastManager
    ...
}

Life-cycle

Create Fast Manager

environment.fastManager.create(id: FastManagerId()).map(AppAction.fastManager)

Destroy Fast Manager

environment.fastManager.destroy(id: FastManagerId()).fireAndForget(),

Operations

Start Speed Test

environment.fastManager.startTest(id: FastManagerId()).fireAndForget()

Stop Speed Test

environment.fastManager.stopTest(id: FastManagerId()).fireAndForget()

Callbacks

case let .didReceive(message: message):
    guard let body = message.body as? NSDictionary,
          let type = body["type"] as? String,
          let units = body["units"] as? String,
          let value = body["value"] as? String else {  return .none }
    
    switch type {
    case "down":
    	// handle download update
        return .none

    case "down-done":
         // handle download completion
        return .none
        
    case "up":
        // handle upload update
        return .none

    case "up-done":
        // handle upload completion
    default:
        return .none
    }
}

License

2020 Joe Blau, MIT

Github

link
Stars: 1

Dependencies

Used By

Total: 0