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

Performant way to using StateReader #168

Merged
merged 8 commits into from Oct 8, 2020
Merged

Conversation

muukii
Copy link
Collaborator

@muukii muukii commented Oct 7, 2020

For better performance, to reduce creating view structure in body property as possible.
We suggest you use Derived object as possible instead of directly passing a Store into StateReader.

The derived object can focus on properties that you need inside StateReader, and emit events of request view update only their changed.
In using the store directly, StateReader also updates itself from the events of unused properties changed.

To solve:
#160

And It contains also writing issues in Xcode.
#165

Before

StateReader(store) { state in
  Text(state.name)
}

After

StateReader(store).content { state in
  Text(state.name)
}

image

@muukii muukii changed the base branch from master to muukii/state-reader October 7, 2020 15:02
@muukii muukii changed the title Muukii/performant state reader [WIP] Muukii/performant state reader Oct 7, 2020
@muukii muukii marked this pull request as draft October 7, 2020 15:02
Base automatically changed from muukii/state-reader to master October 7, 2020 15:32
@muukii muukii changed the title [WIP] Muukii/performant state reader Performant way to using StateReader Oct 7, 2020
@muukii muukii changed the base branch from master to v8.0.0-branch October 7, 2020 18:41
@muukii muukii changed the base branch from v8.0.0-branch to master October 7, 2020 18:41

/** Not working */
@available(iOS 13, *)
final class StateReaderTests: XCTestCase {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried.
but I could not run SwiftUI's view on XCTest.

@@ -0,0 +1,94 @@
//
// ContentView.swift
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A demo application to check the behavior of StateReader

@muukii muukii force-pushed the muukii/performant-state-reader branch from 8e1d223 to b9cc1ef Compare October 7, 2020 18:48
*/
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
public struct StateReader<Value, Content: View>: View {
public struct StateReader<Value>: View {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StateReader is going to be new API

Comment on lines +53 to +61
public var body: EmptyView {
assertionFailure("""
Warning: StateReader still does not have a content-view.
Please add a content by `.content()`.

This issue comes from current auto-completion function doesn't work well.
Probably, it's might be fixed with better syntax.
""")
return EmptyView()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is not cool part

Comment on lines +69 to +71
public func content<NewContent: View>(_ makeContent: @escaping (Changes<Value>) -> NewContent) -> _StateReaderContent<Value, NewContent> {
return .init(updateTrigger: observableObject, updateValue: updateValue, content: makeContent)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to call this to describe content view

/// - content:
public init<Derived: DerivedType>(
_ derived: Derived,
_ map: MemoizeMap<Changes<Derived.Value>, Value>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing MemoizeMap causes the complexity of auto-completion and verbosity of signature.
In most of the cases, it's enough passing Derived object.

If we need to create chained Derived, pass the chained Derived from outside.

@muukii muukii marked this pull request as ready for review October 7, 2020 19:05
@muukii muukii force-pushed the muukii/performant-state-reader branch from 6896002 to 716ffcf Compare October 7, 2020 19:13
@muukii muukii force-pushed the muukii/performant-state-reader branch from 716ffcf to 1f7da19 Compare October 7, 2020 19:17
@muukii muukii merged commit b6f79ce into master Oct 8, 2020
@muukii muukii deleted the muukii/performant-state-reader branch October 8, 2020 03:16
}

@available(*, deprecated, message: "You're returning a value which is not a type of `SwiftUI.View`.")
public func content(_ makeContent: @escaping (Changes<Value>) -> Never) -> Never {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is dummy just for Xcode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant