-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose helpers for static models #311
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,23 +12,17 @@ public struct StaticStorePreviewContext { | |
} | ||
|
||
public func makeStateAccessor<State>(state: State) -> StateAccessor<State> { | ||
StateAccessor( | ||
state: state, | ||
sendValue: { _ in } | ||
) | ||
.constant(state: state) | ||
} | ||
|
||
public func makeActionModel<State, Action>( | ||
state: State | ||
) -> ActionModel<State, Action> { | ||
ActionModel( | ||
accessor: makeStateAccessor(state: state), | ||
sendAction: makeSink(of: Action.self).send | ||
) | ||
.constant(state: state) | ||
} | ||
} | ||
|
||
extension Store { | ||
public extension Store { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the access control on the individual methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but the linter did this! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. approve me! #315 |
||
/// Generates a static store for previews. | ||
/// | ||
/// Previews generated with this method are static and do not update state. To generate a | ||
|
@@ -38,15 +32,15 @@ extension Store { | |
/// - Parameter makeModel: A closure to create the store's model. The provided `context` param | ||
/// is a convenience to generate dummy sinks and state accessors. | ||
/// - Returns: A store for previews. | ||
public static func preview( | ||
static func preview( | ||
makeModel: (StaticStorePreviewContext) -> Model | ||
) -> Store { | ||
let context = StaticStorePreviewContext() | ||
let model = makeModel(context) | ||
let (store, _) = make(model: model) | ||
return store | ||
} | ||
|
||
/// Generates a static store for previews. | ||
/// | ||
/// Previews generated with this method are static and do not update state. To generate a | ||
|
@@ -55,14 +49,14 @@ extension Store { | |
/// | ||
/// - Parameter state: The state of the view. | ||
/// - Returns: A store for previews. | ||
public static func preview<State, Action>( | ||
static func preview<State, Action>( | ||
state: State | ||
) -> Store<ActionModel<State, Action>> where Model == ActionModel<State, Action> { | ||
preview { context in | ||
context.makeActionModel(state: state) | ||
} | ||
} | ||
|
||
/// Generates a static store for previews. | ||
/// | ||
/// Previews generated with this method are static and do not update state. To generate a | ||
|
@@ -71,7 +65,7 @@ extension Store { | |
/// | ||
/// - Parameter state: The state of the view. | ||
/// - Returns: A store for previews. | ||
public static func preview<State>( | ||
static func preview<State>( | ||
state: State | ||
) -> Store<StateAccessor<State>> where Model == StateAccessor<State> { | ||
preview { context in | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any reasons we'd want to restrict clients' ability to create these types in general?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reduce the chance of folks using it wrong, mainly. You can't create something like a
RenderContext
either. The type's docs already hint at this, and I can copy it to the init as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear – you think the convenience of exposing the public constructor outweighs the chance of misuse?