clojurepedestal

Clojure ^shared in namespace


I am following the pedestal tutorial, and I noticed the ^shared annotation in the code, like below :

(ns ^:shared tutorial-client.behavior
    (:require [clojure.string :as string]
              [io.pedestal.app.messages :as msg]))

What is it useful for ?


Solution

  • The ^shared annotation is for indicating to the ClojureScript compiler to compile this .clj file, where it would normally ignore it. This lets you write shared code that can be run on the client and server (as long as it doesn't use platform specific code). This was before cljx and cljc files and AFAIK is specific to the Pedestal build process, not part of vanilla ClojureScript.

    The supported way to write platform specific code is using Reader Conditionals, new in Clojure 1.7.

    As a side note, Pedestal App is effectively deprecated, Pedestal Server is still maintained.