mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 10:21:17 +01:00
Updated README
This commit is contained in:
@@ -68,7 +68,7 @@ extension ForEach where Content: View {
|
||||
/**
|
||||
Creates an instance that creates views for each object in a `ListSnapshot`.
|
||||
```
|
||||
@LiveList
|
||||
@ListState
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
var body: some View {
|
||||
@@ -127,7 +127,7 @@ extension ForEach where Content: View {
|
||||
/**
|
||||
Creates an instance that creates views for `ListSnapshot` sections.
|
||||
```
|
||||
@LiveList
|
||||
@ListState
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
var body: some View {
|
||||
@@ -164,7 +164,7 @@ extension ForEach where Content: View {
|
||||
/**
|
||||
Creates an instance that creates views for each object in a `ListSnapshot.SectionInfo`.
|
||||
```
|
||||
@LiveList
|
||||
@ListState
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -70,7 +70,6 @@ public struct ListReader<Object: DynamicObject, Content: View, Value>: View {
|
||||
|
||||
self._list = .init(listPublisher)
|
||||
self.content = content
|
||||
self.keyPath = \.self
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,8 +97,10 @@ public struct ListReader<Object: DynamicObject, Content: View, Value>: View {
|
||||
) {
|
||||
|
||||
self._list = .init(listPublisher)
|
||||
self.content = content
|
||||
self.keyPath = keyPath
|
||||
self.content = {
|
||||
|
||||
content($0[keyPath: keyPath])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,17 +108,16 @@ public struct ListReader<Object: DynamicObject, Content: View, Value>: View {
|
||||
|
||||
public var body: some View {
|
||||
|
||||
self.content(self.list[keyPath: self.keyPath])
|
||||
self.content(self.list)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@LiveList
|
||||
@ListState
|
||||
private var list: ListSnapshot<Object>
|
||||
|
||||
private let content: (Value) -> Content
|
||||
private let keyPath: KeyPath<ListSnapshot<Object>, Value>
|
||||
private let content: (ListSnapshot<Object>) -> Content
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// LiveList.swift
|
||||
// ListState.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2021 John Rommel Estropia
|
||||
@@ -29,21 +29,21 @@ import Combine
|
||||
import SwiftUI
|
||||
|
||||
|
||||
// MARK: - LiveList
|
||||
// MARK: - ListState
|
||||
|
||||
/**
|
||||
A property wrapper type that can read `ListPublisher` changes.
|
||||
*/
|
||||
@propertyWrapper
|
||||
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
||||
public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
public struct ListState<Object: DynamicObject>: DynamicProperty {
|
||||
|
||||
// MARK: Public
|
||||
|
||||
/**
|
||||
Creates an instance that observes `ListPublisher` changes and exposes a `ListSnapshot` value.
|
||||
```
|
||||
@LiveList
|
||||
@ListState
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
init(listPublisher: ListPublisher<Person>) {
|
||||
@@ -64,7 +64,7 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
}
|
||||
```
|
||||
|
||||
- parameter listPublisher: The `ListPublisher` that the `LiveList` will observe changes for
|
||||
- parameter listPublisher: The `ListPublisher` that the `ListState` will observe changes for
|
||||
*/
|
||||
public init(
|
||||
_ listPublisher: ListPublisher<Object>
|
||||
@@ -76,10 +76,11 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
/**
|
||||
Creates an instance that observes the specified `FetchChainableBuilderType` and exposes a `ListSnapshot` value.
|
||||
```
|
||||
@LiveList(
|
||||
@ListState(
|
||||
From<Person>()
|
||||
.where(\.isMember == true)
|
||||
.orderBy(.ascending(\.lastName))
|
||||
.orderBy(.ascending(\.lastName)),
|
||||
in: Globals.dataStack
|
||||
)
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
@@ -109,11 +110,12 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
/**
|
||||
Creates an instance that observes the specified `SectionMonitorBuilderType` and exposes a `ListSnapshot` value.
|
||||
```
|
||||
@LiveList(
|
||||
@ListState(
|
||||
From<Person>()
|
||||
.sectionBy(\.age)
|
||||
.where(\.isMember == true)
|
||||
.orderBy(.ascending(\.lastName))
|
||||
.orderBy(.ascending(\.lastName)),
|
||||
in: Globals.dataStack
|
||||
)
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
@@ -149,10 +151,11 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
/**
|
||||
Creates an instance that observes the specified `From` and `FetchClause`s and exposes a `ListSnapshot` value.
|
||||
```
|
||||
@LiveList(
|
||||
@ListState(
|
||||
From<Person>(),
|
||||
Where<Person>(\.isMember == true),
|
||||
OrderBy<Person>(.ascending(\.lastName))
|
||||
OrderBy<Person>(.ascending(\.lastName)),
|
||||
in: Globals.dataStack
|
||||
)
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
@@ -184,12 +187,13 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
/**
|
||||
Creates an instance that observes the specified `From` and `FetchClause`s and exposes a `ListSnapshot` value.
|
||||
```
|
||||
@LiveList(
|
||||
@ListState(
|
||||
From<Person>(),
|
||||
[
|
||||
Where<Person>(\.isMember == true),
|
||||
OrderBy<Person>(.ascending(\.lastName))
|
||||
]
|
||||
],
|
||||
in: Globals.dataStack
|
||||
)
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
@@ -221,11 +225,12 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
/**
|
||||
Creates an instance that observes the specified `From`, `SectionBy`, and `FetchClause`s and exposes a sectioned `ListSnapshot` value.
|
||||
```
|
||||
@LiveList(
|
||||
@ListState(
|
||||
From<Person>(),
|
||||
SectionBy(\.age),
|
||||
Where<Person>(\.isMember == true),
|
||||
OrderBy<Person>(.ascending(\.lastName))
|
||||
OrderBy<Person>(.ascending(\.lastName)),
|
||||
in: Globals.dataStack
|
||||
)
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
@@ -265,13 +270,14 @@ public struct LiveList<Object: DynamicObject>: DynamicProperty {
|
||||
/**
|
||||
Creates an instance that observes the specified `From`, `SectionBy`, and `FetchClause`s and exposes a sectioned `ListSnapshot` value.
|
||||
```
|
||||
@LiveList(
|
||||
@ListState(
|
||||
From<Person>(),
|
||||
SectionBy(\.age),
|
||||
[
|
||||
Where<Person>(\.isMember == true),
|
||||
OrderBy<Person>(.ascending(\.lastName))
|
||||
]
|
||||
],
|
||||
in: Globals.dataStack
|
||||
)
|
||||
var people: ListSnapshot<Person>
|
||||
|
||||
@@ -53,7 +53,6 @@ public struct ObjectReader<Object: DynamicObject, Content: View, Placeholder: Vi
|
||||
self._object = .init(objectPublisher)
|
||||
self.content = content
|
||||
self.placeholder = EmptyView.init
|
||||
self.keyPath = \.self
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +71,6 @@ public struct ObjectReader<Object: DynamicObject, Content: View, Placeholder: Vi
|
||||
self._object = .init(objectPublisher)
|
||||
self.content = content
|
||||
self.placeholder = placeholder
|
||||
self.keyPath = \.self
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,9 +87,11 @@ public struct ObjectReader<Object: DynamicObject, Content: View, Placeholder: Vi
|
||||
) where Placeholder == EmptyView {
|
||||
|
||||
self._object = .init(objectPublisher)
|
||||
self.content = content
|
||||
self.content = {
|
||||
|
||||
content($0[keyPath: keyPath])
|
||||
}
|
||||
self.placeholder = EmptyView.init
|
||||
self.keyPath = keyPath
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,9 +110,11 @@ public struct ObjectReader<Object: DynamicObject, Content: View, Placeholder: Vi
|
||||
) where Placeholder == EmptyView {
|
||||
|
||||
self._object = .init(objectPublisher)
|
||||
self.content = content
|
||||
self.content = {
|
||||
|
||||
content($0[keyPath: keyPath])
|
||||
}
|
||||
self.placeholder = placeholder
|
||||
self.keyPath = keyPath
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +124,7 @@ public struct ObjectReader<Object: DynamicObject, Content: View, Placeholder: Vi
|
||||
|
||||
if let object = self.object {
|
||||
|
||||
self.content(object[keyPath: self.keyPath])
|
||||
self.content(object)
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -133,12 +135,11 @@ public struct ObjectReader<Object: DynamicObject, Content: View, Placeholder: Vi
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@LiveObject
|
||||
@ObjectState
|
||||
private var object: ObjectSnapshot<Object>?
|
||||
|
||||
private let content: (Value) -> Content
|
||||
private let content: (ObjectSnapshot<Object>) -> Content
|
||||
private let placeholder: () -> Placeholder
|
||||
private let keyPath: KeyPath<ObjectSnapshot<Object>, Value>
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// LiveObject.swift
|
||||
// ObjectState.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2021 John Rommel Estropia
|
||||
@@ -29,21 +29,21 @@ import Combine
|
||||
import SwiftUI
|
||||
|
||||
|
||||
// MARK: - LiveObject
|
||||
// MARK: - ObjectState
|
||||
|
||||
/**
|
||||
A property wrapper type that can read `ObjectPublisher` changes.
|
||||
*/
|
||||
@propertyWrapper
|
||||
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
|
||||
public struct LiveObject<O: DynamicObject>: DynamicProperty {
|
||||
public struct ObjectState<O: DynamicObject>: DynamicProperty {
|
||||
|
||||
// MARK: Public
|
||||
|
||||
/**
|
||||
Creates an instance that observes `ObjectPublisher` changes and exposes an `Optional<ObjectSnapshot<O>>` value.
|
||||
```
|
||||
@LiveObject
|
||||
@ObjectState
|
||||
var person: ObjectSnapshot<Person>?
|
||||
|
||||
init(objectPublisher: ObjectPublisher<Person>) {
|
||||
@@ -61,7 +61,7 @@ public struct LiveObject<O: DynamicObject>: DynamicProperty {
|
||||
}
|
||||
```
|
||||
|
||||
- parameter objectPublisher: The `ObjectPublisher` that the `LiveObject` will observe changes for
|
||||
- parameter objectPublisher: The `ObjectPublisher` that the `ObjectState` will observe changes for
|
||||
*/
|
||||
public init(_ objectPublisher: ObjectPublisher<O>?) {
|
||||
|
||||
Reference in New Issue
Block a user