This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-10
Channels
- # adventofcode (3)
- # aws (2)
- # beginners (85)
- # boot (8)
- # boot-dev (4)
- # cider (36)
- # clara (3)
- # cljs-dev (87)
- # cljsrn (3)
- # clojure (87)
- # clojure-austin (12)
- # clojure-brasil (1)
- # clojure-dev (8)
- # clojure-dusseldorf (5)
- # clojure-estonia (5)
- # clojure-greece (4)
- # clojure-italy (3)
- # clojure-spec (17)
- # clojure-uk (55)
- # clojurescript (70)
- # core-logic (2)
- # cursive (6)
- # data-science (18)
- # datomic (13)
- # emacs (34)
- # fulcro (347)
- # graphql (12)
- # hoplon (6)
- # jobs (3)
- # jobs-discuss (43)
- # juxt (2)
- # keechma (31)
- # leiningen (29)
- # lumo (2)
- # midje (2)
- # off-topic (118)
- # om-next (4)
- # onyx (39)
- # pedestal (6)
- # re-frame (85)
- # reagent (21)
- # remote-jobs (3)
- # ring (5)
- # rum (2)
- # shadow-cljs (126)
- # spacemacs (1)
- # sql (6)
@tony.kay thought about a bit and I think the implementation should be completely separate from the “API”
@thheller I'll look it over. Surface reaction is that from a technical standpoint it seems solid. From a practical standpoint I need to think more about it. Not sure about the API change. The existing API is more clear I think, and it is more amenable to existing tooling which eases transition (e.g. what if only shadow-cljs implements your suggestion...then the "normal" cljs users lose i18n?
The newer trf accepts named parameters or a single map...the named is for bw compat. Using a map turns out to be more practically useful.
and given the map preference, a change in API to one call might better be:
(tr msgid {:cljs.i18n/context "optional context" ...other params...})
that also makes the API easily extensible: just add more nsed kws to the options map
that also makes it possible to pass additional info and custom options through to the string extraction layer.
and I guess as far as API goes: trc
and trf
of Fulcro are just macros on top of this new macro...so bw compat is easy
does shadow have an existing hook point to use this today? Or would it require new hooks?
@tony.kay hmm I like the map instead of kw-args but what if the map is completely dynamic? we can’t extract :cljs.i18n/context
then?
can’t really call this cljs.i18n
without some sort of approval that this is ok since I consider cljs.
sort of reserved
So, I guess the options are:
- Have a tr with the optional vector notation for context
- Have trc to supply context
- Make the macro error check and disallow variables…actually the current tr does that, since it has to be a literal string or we can’t extract it. There is a tr-unsafe
variant that is unchecked…because sometimes you do need to use a variable for the string.
can add a tr-unsafe fn to the cljs.i18n
ns that just delegates to the ITranslate
protocol as is
but thinking about it .. no matter what the :cljs.i18n/context
is better than the vector notation
Just throwing this out there:
`
(tr “message”)
(tr “context” “message”)
(tr “message {a}” {:a 1})
(tr “context” “message {a}” {:a 1})
Yeah, I understand the problem wit macros….I still lean towards the separate macro name for context
well we dont NEED the args to be static but it feels more explicit and automatically error checks?
in formatted stuff, allowing a dynamic map to fill in params is a requirement of the API
it would be more convenient yes but for error-checking reasons static sounds more reasonable
I mean thing like (tr "hello {name}" :nane username)
which could check if the map contains all the required keys
(defn formatted-user-info [args]
(str (tr "..." args) (when (some-cond? args) (tr "..." args)))
I understand the error checking…and I don’t care about that error checking because it breaks the more interesting and useful cases I do care about
if the message doesn’t format correctly, they see that in the output…no compile check needed
If they fail to use a literal string, then extraction fails…and that would be hard to catch without compiler help…so I do care about that one
(defn formatted-user-info [{:keys [name condition suffix] :as args}]
(str (tr "..." :name name ) (when (some-cond? condition) (tr "..." :suffix suffix)))
and I like the fact that the philosophy of maps in clojure is “I can carry extra stuff and things shouldn’t care”
(defn formatted-user-info [args]
(str (tr "... {some-key}..." args) (when (some-cond? args) (tr "... {other-key} ..." args)))
oh, and just roll context et al into args since you don’t know for sure where the boundary is? I guess that’s ok 🙂
not suggesting trf
is in the core lib…but Fulcro (and other consumers) could provide it
I was thinking through both user API and implementation…co-mingling…separating them back out now
will need a proof of concept impl anyways and fulcro pretty much already has everything in place
the only point of the cljs.i18n
API is pretty much to have something that build tools can access later
shadow-cljs currently doesn’t allow a custom cljs.user
, thats one things I saw in the template
yes :devtools {:before-load ... :after-load ...}
both taking fully qualified symbols
so, to separate code for “just dev” you just make sure not to require it from prod code, right?
https://github.com/shadow-cljs/quickstart-browser/blob/master/src/starter/browser.cljs
hmmm…seems it is different? https://github.com/thheller/shadow-cljs/wiki/ClojureScript-for-the-browser#module-loader
yeah cljs.loader
is not great IMHO. it completely does not work with :module-hash-names
which hashes output files for caching purposed
:module-loader
existed about a year before cljs.loader
so it isn’t built on top of it
not sure if I can rework it to just use that due to the ^:const
injection stuff. makes it really icky to use
um…there was something about the non-manual set-loaded! they tried that didn’t work. It bit me in particular
cool. well, it probably would not be hard to support shadow’s through dynamic resolution
it would be better if cljs.loader
just provided the API and didn’t enforce an implementation as well 😞
ok. Thanks for the tips. I’ll let you know how it goes. The dynamic module loading is a core part of dynamic routing for code splitting and i18n locales
thinking about it some more it might be practical to just create a spec for the analyzer data
Sure. Sounds reasonable. since you’re still around…trying to run CI tests from command line. Seems that is TBD?
only did very basic work on that but I think @mitchelkuijpers is using it
more i18n fun, evidently. I got the stuff to compile with the stuff you and Mitchel had talked about with the intl-messageformat, but when I try the tests it dies on this line of generated js:
shadow.js.shim.module$intl_messageformat = require("intl-messageformat");
saying require
is not found:ci-tests {:target :karma :output-to “target/ci.js” :ns-regexp “^boo\\..*-spec$” :modules {:main {:entries [boo.CI-runner]}}}
covers what :js-provider
means, you are on :require
which is only supposed to be used for node builds
you don’t need https://github.com/awkay/shadow-template/blob/master/src/test/boo/tests_to_run.cljs if the use the :karma
stuff
the :karma
finds all namespaces that matches your regexp and makes sure it is loaded before the :runner-ns
so no manual upkeep with those tests-to-run files, although you can of course still do it manually if you prefer
During development hot code reload is used to trigger test re-render, and all the tests have to be present in the browser or it won’t find them
right .. but … I “hack” into cljs.test
and register all tests so they are available at runtime
but yeah if you stick to the default cljs.test/run-all-tests
that doesn’t buy you anything
with a :browser target it doesn’t know to scan for tests, and without the module thing it wouldn’t run the spec rendering trigger
pretty simple https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/test/browser.cljs
https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/test/env.cljs lets you access all deftest
the point is that the :browser-test
target will ensure that all namespaces matching the regexp will be compiled and loaded before the runner
if you have everything setup so the tests are registered at runtime you don’t need to go the macro route that cljs.test took
there is probably a whole lot more build tools could provide if properly enabled to do so
:test {:target :browser-test
:output-dir "resources/public/tests"
:asset-path "/tests"
:devtools {:after-load boo.client-test-main/start
:before-load boo.client-test-main/stop
:preloads [devtools.preload]
:http-root "resources/public"
:http-port 8021}}
That look right?unfortunately :http-root
currently has to be static part of the configuration so you still need to repeat that
I’m beginning to think what I had was better in some ways…I just want the scanning. The rest of the magic is distracting
I’m convinced that we can probably get a testing setup without any configuration at all
not sure how much shadow-cljs should help with running them, its a build tool after all
well, at least for Fulcro Spec it was built around “it works if you have hot code reload”…no other support was assumed, because there wasn’t any 🙂
yeah but you also generate a whole bunch of files in the template that may confuse users
I prefer generating as little files as possible. also less likely for updates to break stuff just because a generated file is now outdated
:test {:target :browser-test
:test-dir "resources/public/test"
:ns-regexp "^boo\\..*-spec$"
:runner-ns boo.client-test-main
:devtools {:http-port 8021
:preloads [devtools.preload]
:http-root "out/demo-test-dummy"}}
is what I have now…but it does not find my index.html when I try to load:preloads [devtools.preload]
is no longer required as of [email protected]
. it is automatically added if cljs-devtools
is on the classpath
:ns-regexp "-spec$"
is also safe to do since it will only include matching files, eg. nothing in .jar files
I need to push spec’s css into component-local css. I wrote the very early draft of spec, but someone else wrote the bulk of it…it needs some work…
you can :lein {:profile "+cljs"}
and create a dedicated :cljs
profile in project.clj
if desirable
yeah, I’ll probably add that. ANy clue why Karma won’t exit, and then disconnects? I’m calling the done
from stop
I never went beyond running karma start
which re-runs tests on file change so it isn’t supposed to exit
singleRun is supposed to exit so that you can use it with things like Travis and CircleCI
npx karma start --single-run
11 01 2018 00:07:03.055:INFO [karma]: Karma v2.0.0 server started at
11 01 2018 00:07:03.058:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency
11 01 2018 00:07:03.063:INFO [launcher]: Starting browser ChromeHeadless
11 01 2018 00:07:03.314:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Connected on socket c0LoCJjPKzBp3pRIAAAA with id 16697457
LOG: 'Testing shadow.inspect-test'
LOG: '{:type :kv, :type-desc "cljs.core/PersistentArrayMap", :count 1}
'
LOG: '{:type :coll, :type-desc "cljs.core/PersistentHashSet"}
'
LOG: 'Testing demo.app-test'
LOG: 'once before'
LOG: 'each before'
HeadlessChrome 0.0.0 (Mac OS X 10.12.6) demo.app-test a-failing-test FAILED
FAIL in (a-failing-test) (at http:60704:85)
expected: (=
1
2)
actual: (=
1
2)
diff: - 1
+ 2
LOG: 'each after'
LOG: 'each before'
LOG: 'each after'
LOG: 'once after'
LOG: '
Ran 3 tests containing 1 assertions.'
LOG: '1 failures, 0 errors.'
HeadlessChrome 0.0.0 (Mac OS X 10.12.6): Executed 3 of 3 (1 FAILED) (0 secs / 0.011 secs)
HeadlessChrome 0.0.0 (Mac OS X 10.12.6) ERROR
Disconnected, because no message in 10000 ms.
HeadlessChrome 0.0.0 (Mac OS X 10.12.6): Executed 3 of 3 (1 FAILED) DISCONNECTED (10.03 secs / 0.011 secs)
(prn :calling-end-run-tests)
(ct/report {:type :end-run-tests})
(prn :done-end-run-tests)
(defmethod ct/report [::karma :end-run-tests] [_]
(prn :in-end-run-tests)
(js/__karma__.complete #js {"coverage" (aget js/window "__coverage__")}))
should be fixed in [email protected]