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

Extract globals from re-frame state #3285

Merged
merged 18 commits into from
May 27, 2024
Merged

Extract globals from re-frame state #3285

merged 18 commits into from
May 27, 2024

Conversation

aatkin
Copy link
Collaborator

@aatkin aatkin commented Apr 18, 2024

Checklist for author

Remove items that aren't applicable, check items that are done.

Reviewability

  • Link to issue
  • Note if PR is on top of other PR
  • Note if related change in rems-deploy repo
  • Consider adding screenshots for ease of review

Backwards compatibility

  • API is backwards compatible or completely new
  • Events are backwards compatible or have migrations
  • Config is backwards compatible
  • Feature appears correctly in PDF print

Documentation

  • Update changelog if necessary
  • API is documented and shows up in Swagger UI
  • Components are added to guide page
  • Update docs/ (if applicable)
  • Update manual/ (if applicable)
  • ADR for major architectural decisions or experiments
  • New config options in config-defaults.edn

Testing

  • Complex logic is unit tested
  • Valuable features are integration / browser / acceptance tested automatically

Follow-up

  • New tasks are created for pending or remaining tasks

Copy link
Collaborator

@Macroz Macroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty much ready. I think we should consider the spa, app & globals and possibly decide to have just two.

Also we are using direct atom references, but if it reads badly we could use helper functions instead. As long as everything is found with rems.globals then we can change in the future.

src/cljs/rems/config.cljs Outdated Show resolved Hide resolved
@@ -21,7 +21,7 @@

(defn save-roles [response]
(when-let [roles (-get-response-header response "x-rems-roles")]
(rf/dispatch [:set-roles (map keyword (split-words roles))]))
(reset! rems.globals/roles (set (map keyword (split-words roles)))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One difference with using a direct reference here is that there can't be dependency circles, where in re-frame there was one layer of indirection.

The direct reference from rems.ajax to the globals seems a bit odd anyway.

src/cljs/rems/app.cljs Show resolved Hide resolved
src/cljs/rems/config.cljs Outdated Show resolved Hide resolved
src/cljs/rems/globals.cljs Outdated Show resolved Hide resolved
src/cljs/rems/spa.cljs Outdated Show resolved Hide resolved
src/cljs/rems/spa.cljs Outdated Show resolved Hide resolved
;; default language first
(sort (comp not= (:default-language db))
(:languages db))))
(defn- validate-lang [lang]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could simply be

(defn- validate-lang [lang]
  (contains? (set @rems.config/languages) lang))

src/cljs/rems/user_settings.cljs Outdated Show resolved Hide resolved
Comment on lines 71 to 73
(when (and (not (:user-settings db)) ; first time
(not (validate-lang (get-language-cookie)))) ; e.g. unsupported language in cookie
(save-user-language! (:language user-settings)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't save-user-language! already do some of this checking?

@Macroz Macroz marked this pull request as ready for review May 13, 2024 12:38
Base automatically changed from update-reframe to master May 17, 2024 11:35
Most initialization happens in app.cljs and spa.cljs. User settings and language contained a lot of re-frame event spaghetti, which is now reduced to 1 event and a few functions that can be reference jumped into. Language reaction (getter) is slightly simpler, at the expense of doing more during fetching user settings.
Part of the refactoring effort to move static state from re-frame to globals.

As language is pretty much considered to mean "current user language" everywhere, passing it as props through multiple components does not make a lot of sense anymore. Container/view separation might still make sense for some UI parts.
@aatkin aatkin merged commit 5566270 into master May 27, 2024
7 checks passed
@aatkin aatkin deleted the globals branch May 27, 2024 15:09
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

Successfully merging this pull request may close these issues.

None yet

2 participants