mirror of
https://github.com/zhigang1992/Boutique.git
synced 2026-04-29 12:34:52 +08:00
storedValue.binding is now computed property rather than a function
This commit is contained in:
@@ -4,7 +4,7 @@ public extension StoredValue {
|
||||
|
||||
/// A convenient way to create a `Binding` from a `StoredValue`.
|
||||
/// - Returns: A `Binding<Item>` of the `StoredValue<Item>` provided.
|
||||
func binding() -> Binding<Item> {
|
||||
var binding: Binding<Item> {
|
||||
Binding(get: {
|
||||
self.wrappedValue
|
||||
}, set: {
|
||||
@@ -18,7 +18,7 @@ public extension AsyncStoredValue {
|
||||
|
||||
/// A convenient way to create a `Binding` from an `AsyncStoredValue`.
|
||||
/// - Returns: A `Binding<Item>` of the `AsyncStoredValue<Item>` provided.
|
||||
func binding() -> Binding<Item> {
|
||||
var binding: Binding<Item> {
|
||||
Binding(get: {
|
||||
self.wrappedValue
|
||||
}, set: { value in
|
||||
|
||||
@@ -76,10 +76,10 @@ final class AsyncStoredValueTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testStoredBinding() async throws {
|
||||
XCTAssertEqual(self.$storedBinding.binding().wrappedValue, Binding.constant(BoutiqueItem.sweater).wrappedValue)
|
||||
XCTAssertEqual(self.$storedBinding.binding.wrappedValue, Binding.constant(BoutiqueItem.sweater).wrappedValue)
|
||||
|
||||
try await self.$storedBinding.set(BoutiqueItem.belt)
|
||||
XCTAssertEqual(self.$storedBinding.binding().wrappedValue, Binding.constant(BoutiqueItem.belt).wrappedValue)
|
||||
XCTAssertEqual(self.$storedBinding.binding.wrappedValue, Binding.constant(BoutiqueItem.belt).wrappedValue)
|
||||
}
|
||||
|
||||
func testStoredValuePublishedSubscription() async throws {
|
||||
|
||||
@@ -84,11 +84,11 @@ final class StoredValueTests: XCTestCase {
|
||||
|
||||
func testStoredBinding() async throws {
|
||||
// Using wrappedValue for our tests to work around the fact that Binding doesn't conform to Equatable
|
||||
XCTAssertEqual(self.$storedBinding.binding().wrappedValue, Binding.constant(BoutiqueItem.sweater).wrappedValue)
|
||||
XCTAssertEqual(self.$storedBinding.binding.wrappedValue, Binding.constant(BoutiqueItem.sweater).wrappedValue)
|
||||
|
||||
self.$storedBinding.set(BoutiqueItem.belt)
|
||||
|
||||
XCTAssertEqual(self.$storedBinding.binding().wrappedValue, Binding.constant(BoutiqueItem.belt).wrappedValue)
|
||||
XCTAssertEqual(self.$storedBinding.binding.wrappedValue, Binding.constant(BoutiqueItem.belt).wrappedValue)
|
||||
}
|
||||
|
||||
func testPublishedValueSubscription() async throws {
|
||||
|
||||
Reference in New Issue
Block a user