Comments (8)
Yep, we've used that pattern:
-
Your
app-db
has an:active-panel
key containing an id (for the panel being displayed). -
When the user does something navigation-ish (selects a tab, a dropdown or something which changes the active panel), then the associated dispatch looks like this:
(dispatch [:set-active-panel :panel1])
-
Some high level reagent view has a subscription to
:active-panel
and will switch the associated view.
(defn panel1
[]
.....)
(defn high-level-view
[]
(let [active (subscription [:active-panel])]
(fn []
[:div
[div.title "Heading"]
(condp = @active ;; or you could look up in a map
:panel1 [panel1]
:panel2 [panel2])])))
from re-frame.
Seems like you could also hold the majority of your data in local storage, or datascript. Then just pull out what information you need into app-db based on events. That way you only have relevant data in your app-db at any given time. Though your views would still be looking for the presence of certain keys or values in a conditional, or multimethod.
from re-frame.
We put all our data into app-db
. The moment you have data in two places, you have a synchronization problem. Client/Server is bad enough much less adding multiple places in the client.
from re-frame.
I keep all the page definitions, including the render function, uri, and nav menu text in app-db, along with a :current-page key and use a single :show-page handler. Here's an example:
https://github.com/mdhaney/homesale-clj
The main routing code is in the core namespace. You can also look in ui/navbar to see how I use the page definitions to build the nav menu.
Lot's of cleanup to be done still - in the process of removing all the Bootstrap "add 10 classes to do anything useful" style code. But the basic concept has worked for me on several apps.
from re-frame.
I would love to see this covered in the wiki with the same aplomb we see in the excellent README. Navigation has an awkward bi-directional nature that always sets my head spinning:
- Sometimes a change in app state should lead to a change in URL
- Sometimes a change in URL, such as onpopstate & onpageload, should lead to a change in app state.
Can we put the URL on the conveyor belt and treat it the same as we do our <input/>
fields?
A second point of confusion for me: Suppose app-db contains state that is effectively scoped under panel1—for example, the text of a search field, a collection of orders matching that search, and a subset of that collection that the user selected for some upcoming action—and then onpopstate dispatches panel2 to replace panel1. Should panel1's "local" state get removed from app-db? If so, who is responsible for doing that?
I know I would greatly benefit from seeing these nuances of navigation treated in the docs.
from re-frame.
After writing this I realized that panel1 is the "local" state and my second point of confusion is already covered by the README and by the subscription
in the example given above. Oops. Old mutable thinking habits die hard.
It would still be nice to see the bi-directional aspect of navigation treated via the conveyor belt, if it can be.
from re-frame.
I've created a brief placeholder page for further explanation in the Wiki:
https://github.com/Day8/re-frame/wiki/A-Larger-App
from re-frame.
Given we now have a basic wiki entry for this, I'm closing.
If you feel that you'd like to flesh out that Wiki page with some of your experience, please do because it is currently pretty basic.
from re-frame.
Related Issues (20)
- [Enhancement]: Allow enrich to return `nil` HOT 7
- [Enhancement]: Allow subscribe to be safely called from anywhere
- [Enhancement]: Add the UseASubscriptionInAJsEvent page to the FAQs menu in the docs HOT 1
- [Bug]: de-referencing re-frame.db/app-db inside subscription counts as changing data? HOT 1
- [Bug] [Docs]: Simple app example docs out of sync with code in repo
- [Bug]: CSS link path changing with URL HOT 1
- [Enhancement]: Adding syntax sugar :<= for input subscriptions taking the same query vectors. HOT 2
- [Bug]: fix examples projects lockfiles warning HOT 2
- [Enhancement]: Warning on re-registering subs / events (ie name collision detection) improvements HOT 4
- [Enhancement]: reg-event-fx :fx shorthand HOT 3
- [Bug]: Multiple usage of the same standard interceptor creator in global doesn't work HOT 2
- [Enhancement]: Subscriptions that return `nil` or `false` are evaluated regardless of what's in cache HOT 3
- Wenn ich etwas vom Planeten entferne oder davon etwas abbauen, muss ich auch etwas wieder zurückführen damit es im Gleichgewicht bleibt! HOT 1
- [Bug]: Reframe 10x is not being opened with ctrl+h after 1.6.0 HOT 1
- [Enhancement]: Upgrade React dependency to React 18 HOT 3
- Steigende Preise: Die einzige Lösung hier erklärt... HOT 1
- [Bug]: Bump Reagent version up possible?
- Calling `subscribe` in a render fn clashes with reagent optimizations HOT 7
- [Enhancement]: unwrap interceptor should show event id to help locate implementation
- [Bug]: Broken image link in "The Logo Backstory"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from re-frame.