Fork me on GitHub

Hi! Is it ok to use global vars like default-db here in event handlers? Or it is just for the sake of learning purposes there? I don’t think it’s a good approach to use in real apps, it leads to impurity in the first place. However, my college has a different opinion, and he encourages using global vars like default-db in event handlers.


100% OK. default-db is immutable. The fact that it's a global thing is irrelevant - as long as it's kept as an immutable constant. After all, you're relying all the time on things like assoc - and it's just a global var itself.


Thanks. I understand that it is immutable — a constant. But if you have many such constants which are using in many event handlers and subs, it’s getting harder to maintain the code.


If you extract every single constant thing to the top-level - sure, I agree. But if it's used multiple times or semantically belongs to some existing namespace - definitely extract and name it.


In that particular case that you linked default-db absolutely deserves to be put into db.cljs - it belongs there. All DB-related things go there.