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 there any co-currency management for a single store? #156

Closed
fans3210 opened this issue Oct 19, 2018 · 2 comments
Closed

Is there any co-currency management for a single store? #156

fans3210 opened this issue Oct 19, 2018 · 2 comments

Comments

@fans3210
Copy link

Hi, this framework is amazing. I'm super interested in any redux implementation on IOS, eg: ReSwift.
Have a scenario of concurrent action dispatch:
Eg. Concurrent media files downloading in real time chatting. We need to handle the progress and state of all media files. We can use a dictionary to hold the states of all file states. For each chat bubble cell or viewmodel, we can add a event subscriber to listen to the state change and filter the state of the file for this bubble. For Reswift, they only have single queue support for each store. You cannot dispatch actions concurrently. So how does this framework handle this case? Do I have to use multiple stores?

@bolismauro
Copy link
Contributor

Hi! Sorry for the very late response.

I don' get why you need concurrent dispatches. Isn't it enough some like this (very simplified example code):

State & Actions:

enum DownloadState {
  case notStarted
  case progress(Double)
  case done
}

// mediaID is a string or something
let media: [MediaID: DownloadState]


struct DownloadMedia: AsyncAction, ActionWithSideEffect {
  let id: MediaID

  // update states to handle start, progress and completion

  sideEffect() {

     let progressClosure = { progress in
       dispatch(self.progressAction({ $0.progress = progress })
     }


     let completionClosure = { localURL in
       dispatch(self.completionAction({ $0.progress = progress })
     }

     dependencies.apiManager.getMedia(self.id, progressClosure, completionClosure)
  }
}

Actions are always sequential, but it doesn't matter because the download is actually parallel if yiu dispatch many DownloadMedia.

For the UI you can attach a listener to the store in the vc that handles the collection/table of bubbles instead of using a listener for each bubble.
Take a look at Tempura, if you haven't seen it https://github.com/BendingSpoons/tempura-swift

I hope it is more clear now

@fans3210
Copy link
Author

@bolismauro , failed to receive notifications from your reply. Thanks a lot for the explanation. I would have a try of this framework. For Reswift, we need to manaage the serial queue manually to make sure all actions dispatched are in the same serial queue to make sure they are sequential

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