Object connection specification
This is the engineering specification for an object MotionObservable connection implementation.
MVP
Return a motion observable
return MotionObservable { observer in
// Connect to a source
return {
// Disconnect from the source
}
}
Define a Connection object
Is a private class that represents a single connection.
private final class SomeConnection {
Connection is initialized with the observer and any state information
Both values must be stored by the connection.
class SomeConnection {
init(state: SomeState, observer: MotionObserver<T>)
Add self as an observer
This should be done at the time of construction.
class SomeConnection {
init(state: SomeState, observer: MotionObserver<T>) {
...
state.addTarget(self, action: #selector(event))
Propagate events to the observer
Propagate the gesture when the gesture event callback is invoked.
class SomeConnection {
private func event(data: Data) {
propagate(data)
}