Code Monkey home page Code Monkey logo

Comments (6)

juggernate avatar juggernate commented on May 30, 2024 2

Very interested in this. @Ben-G I saw your unidirectional talk on realm.io and also followed the simple tutorial that came later https://realm.io/news/unidirectional-data-flow-in-swift/
Would love to see a similar example of how to do one way flow using ReSwift with Realm for state persistence.

from reswift.

dustintownsend avatar dustintownsend commented on May 30, 2024 2

@Ben-G is there any update on this? Where you able to create any documentation?

I started moving one of our newer smallish projects to ReSwift after seeing your talk from Realm. I got all the current viewcontrollers moved over and the router set-up as well. I also recently read the unidirectional data flow in swift tutorial from Realm that shows a simple implementation of using Realm as store.

It gave me the idea of a possible ReSwift and Realm integration. I'm curious what you think about this.
Here are some of my thoughts on this:

  • The store would mostly be Realm. Use Realm notifications to push changes to subscribers. Maybe have a RealmStoreSubscriber protocol? Or maybe a RealmStore class that could manage the NotificationTokens/subscriptions?
  • I think Reducers could be eliminated, since I believe that Realm could handle this. I maybe mistaking on this, but if Realm was able to handle them it could reduce a lot of boilerplate code.
  • Actions would just make calls to Realm. So, they would be functions instead of properties like in most of the ReSwift examples. I'm not sure if this would be acceptable.
  • It seems over all that Realm fits nicely into ReSwift or at-least Unidirectional State/Data Flow.

I think the main benefits of this would be eliminating the need to code reducers and getting local persistence for free. Also, I think using Realm Results as state would be interesting.

I had some other ideas as well. Like what you said treat the local persistence (Realm in my case) like a web service. For cases where we need to sync a lot of data I was thinking the service that does the syncing could update the Realm directly and the Realm could send notifications to update the state, but if the state is also trying to update the Realm there might be an issue there.

from reswift.

Ben-G avatar Ben-G commented on May 30, 2024 2

@dustintownsend Someone asked a very similar question in #110 - so I would suggest moving the discussion there for now as we have a nice clean slate to discuss how db persistence should work with ReSwift.

Regarding your points:

  • The store would mostly be Realm. Use Realm notifications to push changes to subscribers. Maybe have a RealmStoreSubscriber protocol? Or maybe a RealmStore class that could manage the NotificationTokens/subscriptions?
  • I think Reducers could be eliminated, since I believe that Realm could handle this. I maybe mistaking on this, but if Realm was able to handle them it could reduce a lot of boilerplate code.
  • Actions would just make calls to Realm. So, they would be functions instead of properties like in most of the ReSwift examples. I'm not sure if this would be acceptable.
  • It seems over all that Realm fits nicely into ReSwift or at-least Unidirectional State/Data Flow.

Using a database as the core of your architecture instead of stores & reducers is a vastly different approach from the on that ReSwift is taking. Therefore this idea is a little outside of the scope of this repo.

The main idea of ReSwift is to have the entire app state in memory. This includes view state and other temporary state that will not be persisted to disk. This is only possible because in memory reads/writes are really fast. Accomplishing this with a file system db is impractical (you also would not want to store the view state in your db).

ReSwift itself really only provides a state management & propagation mechanism. Persistence can be implemented in many different ways.

Will continue this discussion in #110.

from reswift.

Ben-G avatar Ben-G commented on May 30, 2024

Thanks for the question!

The state itself only lives in memory and is not stored to disk. I will document an approach on how to use Swift Flow together with a local persistence layer.

The gist is, that you will treat the DB similar to a webservice - as an outside resource that you can query and that can add new data to your in-memory state.

I will leave this issue open until we have added some documentation for this scenario.

from reswift.

dennisfarandy avatar dennisfarandy commented on May 30, 2024

nice! I'm waiting for using it in production then 👍

from reswift.

camel113 avatar camel113 commented on May 30, 2024

@juggernate +1

from reswift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.