improve Pokedex demo

This commit is contained in:
John Estropia
2020-08-29 20:02:05 +09:00
parent 1db91fcec3
commit 1c735a9228
18 changed files with 820 additions and 426 deletions

View File

@@ -113,9 +113,14 @@ public final class ListPublisher<O: DynamicObject>: Hashable {
Calling `addObserver(_:_:)` multiple times on the same observer is safe.
- parameter observer: an object to become owner of the specified `callback`
- parameter notifyInitial: if `true`, the callback is executed immediately with the current publisher state. Otherwise only succeeding updates will notify the observer. Default value is `false`.
- parameter callback: the closure to execute when changes occur
*/
public func addObserver<T: AnyObject>(_ observer: T, _ callback: @escaping (ListPublisher<O>) -> Void) {
public func addObserver<T: AnyObject>(
_ observer: T,
notifyInitial: Bool = false,
_ callback: @escaping (ListPublisher<O>) -> Void
) {
Internals.assert(
Thread.isMainThread,
@@ -125,6 +130,10 @@ public final class ListPublisher<O: DynamicObject>: Hashable {
Internals.Closure(callback),
forKey: observer
)
if notifyInitial {
callback(self)
}
}
/**

View File

@@ -83,9 +83,14 @@ public final class ObjectPublisher<O: DynamicObject>: ObjectRepresentation, Hash
Calling `addObserver(_:_:)` multiple times on the same observer is safe.
- parameter observer: an object to become owner of the specified `callback`
- parameter notifyInitial: if `true`, the callback is executed immediately with the current publisher state. Otherwise only succeeding updates will notify the observer. Default value is `false`.
- parameter callback: the closure to execute when changes occur
*/
public func addObserver<T: AnyObject>(_ observer: T, _ callback: @escaping (ObjectPublisher<O>) -> Void) {
public func addObserver<T: AnyObject>(
_ observer: T,
notifyInitial: Bool = false,
_ callback: @escaping (ObjectPublisher<O>) -> Void
) {
Internals.assert(
Thread.isMainThread,
@@ -96,6 +101,11 @@ public final class ObjectPublisher<O: DynamicObject>: ObjectRepresentation, Hash
forKey: observer
)
_ = self.lazySnapshot
if notifyInitial {
callback(self)
}
}
/**