Skip to content
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

Standard inputs and outputs for view model #18

Open
lm2343635 opened this issue Feb 4, 2020 · 0 comments
Open

Standard inputs and outputs for view model #18

lm2343635 opened this issue Feb 4, 2020 · 0 comments

Comments

@lm2343635
Copy link
Contributor

The inputs/outputs model helps to make the data exchanging more standard.
https://github.com/kickstarter/native-docs/blob/master/inputs-outputs.md

Swift

Inputs

All input variables MutableProperty types that are invoked directly when needed from the view. The input setter function will set its appropriate member variable with the appropriate input parameter.

fileprivate let projectTappedProperty = MutableProperty<Project?>(nil)
public func projectTapped(_ project: Project) {
    self.projectTappedProperty.value = project
}

Note that the input variable is named with a Property suffix to clarify that it is a MutableProperty. Its function is the name of the action.

If an input value is void, use the following syntax:

fileprivate let viewDidLoadProperty = MutableProperty()
public func viewDidLoad() {
    self.viewDidLoadProperty.value = ()
}

Outputs

All output variables are Signal types with NoError as the second error parameter.

public let goToDiscovery: Signal<DiscoveryParams, NoError>

Note that Xcode will display an error on your output until it is instantiated in the view model's init(). You may set the output to .empty if you wish to continue without implementing, i.e. for testing purposes.

public let goToDiscovery: Signal<DiscoveryParams, NoError> = .empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant