It just depends, for applications yes this may be a better idea. It may or
may not be the right approach for general purpose libraries that want to
supply code for both Node.js and non-Node.js targets.

David

On Tue, Mar 10, 2015 at 7:10 AM, Thomas Heller <[email protected]> wrote:

> IMHO that is not something you should handle at compile time. I would
> suggest creating a proper API and a "main" namespace that serves as an
> entry point to your application and configures it before starting.
>
> For example:
>
> (ns my-app.log)
>
> (defprotocol ILog
>   (-log [this msg]))
>
> (def logger (atom nil))
>
> (def set-logger! [new-log]
>   (reset! logger new-log))
>
> (def log [something]
>   ;; call protocol fn
>   (-log @logger something))
>
> Note that the protocol might not be needed it just expresses a proper API
> and doesn't rely on there being a obj.log function.
>
> Then one "main" for nodejs:
>
> (ns my-app.start-node
>   (:require [my-app.log :as log]))
>
> (log/set-logger! something-from-node-wrapped-in-reify)
>
> (start-my-app)
>
> or something similar for the browser. CLJS recently got support for :main
> and everyone should use it.
>
> Just my 2 cents,
> /thomas
>
>
> On Tuesday, March 10, 2015 at 11:53:25 AM UTC+1, Greg wrote:
> > I have a project which targets both Node.js and the browser - the vast
> majority of code is shared and kept in the 'src' folder, with anything that
> needs to differ being held in 'src-client' and 'src-server'. It's getting a
> little clunky to maintain this, though, so I'm hoping to move everything to
> a single folder and use a macro to detect whether or not it's built with
> Node extensions.
> >
> > Essentially, I want to allow something like this:
> > (def logger
> >     (client-or-server
> >         js/log ; Use a globally namespaced library on the client
> >         (nodejs/require "loglevel") ; Use a 'require' statement on the
> server
> > ))
> >
> > But I'm finding myself a little lost in documentation when it comes to
> safely detecting the existence of 'cljs.nodejs', and I'm wondering if it
> might be a bad idea for as-yet unforeseen reasons?
>
> --
> 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.
>

-- 
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