It sounds to me like you may be thinking about this backwards. You don’t
necessarily want to (enable-console-print!) *any* time that code is run,
just when you’re running your entire app. Rather than require that code
from each of your files, I’d suggest putting it at the top of (or requiring
it from) the entrypoint into your application, and possibly a dev-specific
entrypoint. For instance, in the Chestnut template, there’s a namespace
loaded only in dev
<https://github.com/plexus/chestnut/blob/master/src/leiningen/new/chestnut/env/dev/cljs/chestnut/dev.cljs>
which kicks off the rest of the application. There’s a similar one from
production
<https://github.com/plexus/chestnut/blob/93346e6383b9ca16d1f41e0cd63829cdb6337a7a/src/leiningen/new/chestnut/env/prod/cljs/chestnut/prod.cljs>
which doesn’t load development concerns.

Doing it this way keeps your “real” code blissfully unaware of the way it’s
being used. (And it’s a lot easier than requiring a utility namespace in
every file for the sake of side-effects.)

Peter

On Tue, Nov 11, 2014 at 5:34 AM, Yehonathan Sharvit <[email protected]>
wrote:

It’s very cumbersome to add  (:require [init]) manually to each file.
> Is there another solution?
>
> —
> Sent from Mailbox <https://www.dropbox.com/mailbox>
>
>
> On Mon, Nov 10, 2014 at 4:43 PM, Thomas Heller <[email protected]>
> wrote:
>
>> That SHOULD be handled via the dependency graph of your namespaces, that
>> means if one namespace requires code from another to be loaded it should
>> list it in its (:require ...) declaration. This way you ensure that it was
>> loaded in the right order.
>>
>> init.cljs:
>>
>> (ns init)
>>
>> (enable-console-print!)
>> ..
>>
>> something.cljs:
>>
>> (ns something
>> (:require [init]))
>>
>>
>> As for compilation I cannot speak for other tools (like lein-cljsbuild)
>> but shadow-build [1] compiles in the mentioned order. As long as the (ns
>> ..) declaration is correct I expect other tools to do the right thing too.
>>
>> HTH,
>> /thomas
>>
>> [1] https://github.com/thheller/shadow-build
>>
>> On Monday, November 10, 2014 3:10:49 PM UTC+1, Yehonathan Sharvit wrote:
>> > In my project I have a file: init.cljs with initialization code.
>> >
>> > For instance:
>> > (enable-console-print!)
>> >
>> > (extend-type js/RegExp ;; allow regexp to be called
>> https://gist.github.com/alandipert/2346460
>> > IFn
>> > (-invoke ([this s] (re-matches this s))))
>> >
>> > What is the best way to make sure init.cljs is compiled before the rest
>> of the project?
>>
>> --
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "ClojureScript" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/clojurescript/mDI0HKfSrg4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/clojurescript.
>>
>
>  --
> 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 post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>
​
-- 
Visuals: http://youtube.com/peeja
Words: http://blog.peeja.com/
Conversation: (603) 548-1203

-- 
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to