Go to file
Zach Eriksen 9e04c70567
Merge pull request #2 from 0xLeif/develop
0.0.2
2021-03-16 18:57:58 -05:00
.swiftpm/xcode/package.xcworkspace Initial Commit 2021-03-01 17:34:55 -06:00
Sources/Observation Added public access to value 2021-03-16 18:22:29 -05:00
Tests Remove property wrapper variable 2021-03-01 21:36:31 -06:00
.gitignore Initial Commit 2021-03-01 17:34:55 -06:00
LICENSE Create LICENSE 2021-03-01 22:06:17 -06:00
Package.resolved Initial Commit 2021-03-01 21:29:53 -06:00
Package.swift Initial Commit 2021-03-01 21:29:53 -06:00
README.md Update README.md 2021-03-01 21:55:52 -06:00

README.md

Observation

What is this

This is a work in progress project to experiment with Chain and E.num in useful ways.

Dependencies

E.num

Variable

public enum Variable: Hashable {
    case void
    case bool(Bool)
    case int(Int)
    case float(Float)
    case double(Double)
    case string(String)
    case set(Set<Variable>)
    case array([Variable])
    case dictionary([Variable: Variable])
}

Function

public enum Function {
    case void(() -> ())
    case `in`((Variable) -> ())
    case out(() -> Variable)
    case `inout`((Variable) -> Variable)
}

Chain

public indirect enum Chain {
    case end
    case complete(E.Function?)
    case link(E.Function, Chain)
    case background(E.Function, Chain)
    case multi([Chain])
}

Example Code

let observedValue: ObservedValue<Int> = ObservedValue()

observedValue.didChangeHandler = .complete(
    .void {
        sleep(1)
        print("Done!")
        XCTAssertNotNil(observedValue.value)
    }
)

observedValue.update(value: 5)
observedValue.update(value: 15)
observedValue.update(value: 25)

Property Wrapper

@Observed var index = 4

_index.didChangeHandler = .link(
    .void {
        viewModel.update(value: values[index])
    },
    .complete(
        .void {
            updateUI()
        }
    )
)

guard values.count < index && index >= 0 else {
    return
}

index += 1