Hello everyone,
I'm trying to implement a rudimentary feature-flagging system in CLJS, and
as you might expect, I want to emit different code when a particular
feature is enabled VS disabled. So this is how I started:
```
(ns app.features
(:require [clojure.string :as str]))
(goog-define features "")
(def CURRENT (into #{} (map keyword) (str/split features #",")))
```
I now want to define a simple macro like the following:
```
(defmacro with-feature
[id enabled disabled]
(if (contains? app.features/CURRENT id)
(when (some? enabled) `~enabled)
(when (some? disabled) `~disabled)))
```
Where do I put this macro so that the compiler doesn't complain that `
app.features/CURRENT` cannot be resolved? I know it has to be a .clj file,
but I am unable to require cljs namespaces from clj. I can make the whole
thing work, if I emit the entire `if` expression from the macro (i.e.
backtick the `if` expression), but if possible I'd like to avoid doing that
check at runtime, simply because everything I need to make the decision is
a compile-time constant. Here are two examples of how i want to call it
(from various namespaces):
```
;; in this case enabling the feature adds code, so there is no `disabled`
expression
(features/with-feature :keycloak
(rf/dispatch-sync [::keycloak.events/connect app.config/keycloak])
nil)
;; in this case disabling the feature adds code so there is no `enabled`
expression
(features/with-feature :keycloak
nil
(rf/reg-event-fx ::sign-out-button-clicked
(fn [{:keys [db]} _]
(-> (auth-db/get-session db)
(auth-api/sign-out)))))
```
Is that at all possible? Any help whatsoever is greatly appreciated - many
thanks in advance...
Dimitrios
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/clojurescript/a70f23dd-1447-4082-8c8b-e90929e3e98cn%40googlegroups.com.