Skip to content

Commit ab3afe8

Browse files
authored
Add a read only subscript to ObservableModel (#358)
https://square.slack.com/archives/CBZJ5V163/p1751313246347059 UI-8947 When you have a screen with a model type of `ActionModel<MyWorkflow.State, MyWorkflow.Action>`, you were unable to use a `let` or computed `var` property on your state model, and reference it on that screen. If you did you would get a compiler error of `Cannot assign to property: 'enableDoneButton' is a 'let' constant`, even if you were only trying to read the property. ## Checklist - [ ] Unit Tests - There aren't any tests of `ObservableModel` in the codebase currently. As I'm not very familiar with this codebase, I don't know how to really make a useful test here. - [ ] UI Tests - [ ] Snapshot Tests (iOS only) - [ ] I have made corresponding changes to the documentation
1 parent 175e690 commit ab3afe8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

WorkflowSwiftUI/Sources/ObservableModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,9 @@ extension ObservableModel {
147147
accessor.sendValue { $0[keyPath: keyPath] = newValue }
148148
}
149149
}
150+
151+
/// Allows dynamic member lookup to read state through the accessor.
152+
public subscript<T>(dynamicMember keyPath: KeyPath<State, T>) -> T {
153+
accessor.state[keyPath: keyPath]
154+
}
150155
}

0 commit comments

Comments
 (0)