This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-18
Channels
- # admin-announcements (4)
- # beginners (306)
- # boot (191)
- # bristol-clojurians (4)
- # business (3)
- # cbus (4)
- # cider (6)
- # cljsrn (51)
- # clojure (147)
- # clojure-canada (1)
- # clojure-conj (6)
- # clojure-japan (2)
- # clojure-poland (8)
- # clojure-russia (57)
- # clojure-sg (1)
- # clojurecup (1)
- # clojurescript (229)
- # core-async (4)
- # cursive (47)
- # data-science (2)
- # datomic (3)
- # emacs (6)
- # events (1)
- # hoplon (16)
- # immutant (33)
- # jobs (1)
- # ldnclj (7)
- # off-topic (25)
- # om (69)
- # onyx (7)
- # re-frame (35)
- # reagent (3)
- # yada (4)
I have a couple of questions about structuring large re-frame applications. First, what’s a good way to name events? Second, what is a good folder structure? The wiki has a page on large applications, but the answer is basically to split your app into multiple “panels” = app-dbs, which is something I’d like to avoid.
Let’s say I have a bunch of views and each of them have a delete-button. Should they all just dispatch events called :<view-name>-delete-pressed or something like that?
@kauko: One thing that's more idiomatic than :namespace-delete-pressed
is to use :namespace/delete-pressed
. / is just a regular old character which is permitted in a keyword, but it signifies a namespace.
I have a medium-large re-frame app... what we do is have handlers.cljs hold all the handlers, subs.cljs hold all the subscription, and the views are in a views directory ala views/this-component.cljs
and with event naming, I think just unique names is best, and make it obvious what args a handler expects.
The upside is that all the handlers or subs are in 1 place each, and this is tooling dependant, but helm multi-occur
lets me search through and find them very easily. Also if a sub or handler is used in multiple places I never have to decide where to put it.
Also, I just think that having 1000+ loc files is something that should be avoided, and in apps the size I’m working on we would get there very quickly
I don’t see why :some-view/typed-in-date-field
should be in the same namespace as :some-totally-different-view/location-data-received
Hello, I'm trying to do an ajax search as you type component. What would be the best approach to this. Wrapping the dispatch event in a setTimeout / clearTimeout?
I can see how it can be a good idea to register handlers in different namespaces (like ones that are parallel to the view in question). This is pedantic, but all the handlers are literally in the same "namespace" meaning (register-handler :continue-clicked) from different places will over-write one-another, which is why rightly opted for namespaced keywords
weird thought: you can actually use different clojure namespaces, with the ::a type of keyword.
then naming them something like ::request, ::submit, ::input-validated might work nicely
But I guess it would only help for one namespace. For example, I could have (register-handler ::foobar)
in namespace handler.foobar
, but in view.foobar
I would have to do (dispatch :handler.foobar/foobar)
@kauko you wouldn't need to do (dispatch :handler.foobar/foobar)
if you require and alias the handler.foobar namespace.
(ns view.foobar
(:require [handler.foobar :as f]))
(dispatch ::f/foobar)
@kauko: you can pass parameters to handlers, so if you have a lot of similar handlers, you could combine them
@escherize: keywords can have a namespace to them
they are special, /
isn’t just another character in a keyword
cljs.user=> (namespace :myns/mykw)
"myns"
cljs.user=> (name :myns/mykw)
"mykw"
you are correct @danielcompton. I always assumed clojure.core/namespace just did a sketchy string -> kw conversion. but TIL it's actually a piece of java. http://grepcode.com/file/repo1.maven.org/maven2/org.clojure/clojure/1.7.0/clojure/lang/Symbol.java#21