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

Is it okay to use a class instead of a struct for a store? #14

Closed
mycroftcanner opened this issue Sep 28, 2019 · 3 comments
Closed

Is it okay to use a class instead of a struct for a store? #14

mycroftcanner opened this issue Sep 28, 2019 · 3 comments

Comments

@mycroftcanner
Copy link

I am really struggling with this:

struct RequestLocation: ActionType {
  let location: CLLocation

  func reduce(context: TransactionContext<Store<LocationStore>, Self>) {
    defer {
      // Remember to always call `fulfill` to signal the completion of this operation.
      context.fulfill()
    }
    context.reduceModel { store -> (Void) in
      CoreLocationProxy().locationPublisher().map { location in
        store.location = location
      }
    }
  }
}

Compile error: Escaping closure captures 'inout' parameter 'store'

    context.reduceModel { store -> (Void) in
      store.requestLocationCancellable = store.proxy.locationPublisher().assign(to: \LocationStore.location, on: store)
    }

Compile error: Cannot convert value of type 'WritableKeyPath<LocationStore, CLLocation>' to expected argument type 'ReferenceWritableKeyPath<_, CLLocation>'

I don't see how to make this work without turning my store into a class. It works then. Would that code any issue?

Some more examples using publishers, etc would be quite useful btw.

@mycroftcanner
Copy link
Author

Fatal error: 'value' must be a struct.: ... SourcePackages/checkouts/Store/Sources/Store/Store.swift, line 11

@mycroftcanner
Copy link
Author

mycroftcanner commented Sep 28, 2019

    context.reduceModel { store -> (Void) in
      store.requestLocationCancellable = store.proxy.locationPublisher()
        .receive(on: RunLoop.main)
        .sink(receiveValue: { location in
          os_log("%d %d", location.coordinate.latitude, location.coordinate.longitude)
        })
    }

2019-09-28 11:52:12.184292+0200 Rwork[4975:1328021] 365060354 546416308
2019-09-28 11:52:12.185092+0200 Rwork[4975:1328248] [primary] ▩ (-LprHE5JItuRfMQlwYz8) RequestLocation [2.693875s ms]

this works but I can't figure out a way to mutate my store... Escaping closure captures 'inout' parameter 'store'

@alexdrone
Copy link
Owner

Do you still have issues with this?

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

2 participants