Giter VIP home page Giter VIP logo

Comments (8)

mike-thompson-day8 avatar mike-thompson-day8 commented on September 12, 2024

Yep, we've used that pattern:

  1. Your app-db has an :active-panel key containing an id (for the panel being displayed).

  2. 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])

  3. 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.

taylorSando avatar taylorSando commented on September 12, 2024

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.

mike-thompson-day8 avatar mike-thompson-day8 commented on September 12, 2024

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.

mdhaney avatar mdhaney commented on September 12, 2024

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.

gaconnet avatar gaconnet commented on September 12, 2024

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.

gaconnet avatar gaconnet commented on September 12, 2024

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.

mike-thompson-day8 avatar mike-thompson-day8 commented on September 12, 2024

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.

mike-thompson-day8 avatar mike-thompson-day8 commented on September 12, 2024

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)

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.