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

Global state #1

Closed
pepe opened this issue Feb 9, 2017 · 15 comments
Closed

Global state #1

pepe opened this issue Feb 9, 2017 · 15 comments

Comments

@pepe
Copy link

pepe commented Feb 9, 2017

Hello.

Funny thing, as I was developing https://github.com/pepe/showrum yesterday, I came to the edge of what is feasible with simple hash and methods and started to think about how to continue. And in the morning I found scrum 👍. Thank you very much for it, I love OpenSource!

As I was looking into the code, I found that DB is global for the library (and makes it a framework?), which brought to my mind this issue day8/re-frame#107 by @darwin in re-frame (which I was using extensively, but abandon it lately). I am still not sure, if it is actually problem or not, I just want to bring it to your attention.

Again, thank you, I will try to move showrum to scrum ASAP.

@roman01la
Copy link
Collaborator

Hey @pepe. Thanks, I'm glad you found this useful :)
I'm also concerned about global state, but don't really know at the moment how do decouple it in a nice way. If you have any ideas, it would be great to discuss here, maybe we can do something about it.

@pepe
Copy link
Author

pepe commented Feb 9, 2017

Great, first step I would like to make is to use your lib, and see how it fits my needs.

Thank you again.

@jeroenvandijk
Copy link

Hi @pepe and @roman01la thanks for your work. I was pointed to your library by a co-worker, as I was trying to do something similarly yesterday. I have the same idea/approach of what you want and one of my main goals is to get rid of global state (i.e. only at the root of the application).

This is my example code which looks pretty similar to your solution actually, and I swear I just saw your library.

Here is how I avoid global state, by passing my quasi reconsiler during mounting

Hope you see the common intention. Maybe it helps you to develop this idea further. My inspiration is om.next and I hope to combine it's parser and indexer with this approach.

@roman01la
Copy link
Collaborator

Hi @jeroenvandijk. So you basically passing the state Atom down through components tree and using it as a pub/sub mechanism to communicate data between components?

@roman01la
Copy link
Collaborator

I've been thinking about how to avoid global state and the only solution I see is to pass it directly to every component, from the root. I like this approach because it is explicit. On the other hand this introduces unnecessary dependencies in components and makes it impossible to apply rendering optimizations.

Another way of avoiding global state is to rely on React's Context API, which is usually used to pass data implicitly to every component in a tree. This is how for example Redux works in JavaScript.

@arichiardi
Copy link

Hey guys, in the re-frame issue above the general semiconsent was to use the context indeed. Maybe it is time for us to try 😀😀

@roman01la
Copy link
Collaborator

@arichiardi Yeah, I think I might go this way. But that's doesn't really matter.

I've been hacking this evening on @jeroenvandijk idea and ended up with a reconciler type which is basically an atom + controllers. Though I'm not sure if this is a good idea to introduce own atom.

(def r (sr/reconciler (atom {}) {:counter curl/counter}))

@r ;; {}

(sr/broadcast! r :init)

@r ;; {:count 0}

(sr/dispatch! r :counter :inc)

@r ;; {:count 1}

@jeroenvandijk
Copy link

jeroenvandijk commented Feb 11, 2017 via email

@roman01la
Copy link
Collaborator

roman01la commented Feb 12, 2017

Just updated master with a new architecture built around reconciler thing. Also updated an example code, so you can see how it works now example/counter/core.cljs

Notable changes

  • Reconciler is a ref type which holds application state (atom) and controllers map.
    A key of a controller in the map is where controller's state will be placed in app state.

    (scrum/reconciler (atom {}) {:counter control})

  • A controller no longer has access to a whole app state, instead it will receive only a portion of state associated with a key used to register this controller, when creating reconciler.

Still looking into how to handle async stuff...

@pepe
Copy link
Author

pepe commented Feb 13, 2017

I am almost done with the transfer of showrum to scrum (flu got in the way), so I extend it for a new stuff. Great work @roman01la! Highly appreciated!

@pepe
Copy link
Author

pepe commented Feb 13, 2017

So after a just quick look into the code, it seems very good. Tonite I will move the showrum to the new codebase.

@roman01la
Copy link
Collaborator

@pepe Cool! Looking forward to see what you have there.

@pepe
Copy link
Author

pepe commented Feb 13, 2017

@roman01la at https://github.com/pepe/showrum/tree/scrum you can see the version with the latest scrum (which is part of the ./src as it is not yet released). The showrum code sure needs some refactoring, but it is working as intended and is quite big, so we have the good test bed.

Also, I looked through the new scrum code and it seem much clearer to my eyes.

I am very happy with the result! 👍

@roman01la
Copy link
Collaborator

@pepe Nice! Do you have any concerns so far? FYI I've published from master as 1.0.0-SNAPSHOT

@pepe
Copy link
Author

pepe commented Feb 14, 2017

Thanks. No concerns so far. Truth is, I quite like this super simple approach. And there doesn' t seem to be any speed penalties so far.

The only thing (as you mentioned in the roadmap) is the effects handling.

I think this issue could be closed 😉, thank you very much.

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

4 participants