### Starting mount and getting affected states in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code demonstrates how `mount/start` returns a map containing a vector of the states that were started, in the order they were affected. ```Clojure dev=> (mount/start) {:started [#'app.config/config #'app.nyse/conn #'app/nrepl]} ``` -------------------------------- ### Application Entry Point with Argument Parsing (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet shows an example of an application entry point (`-main`) that parses arguments using the `parse-args` function and then starts the Mount application with the parsed arguments. It combines the argument parsing and Mount initialization steps. Requires a `parse-args` function to be defined. ```Clojure (defn -main [& args] (mount/start-with-args (parse-args args))) ``` -------------------------------- ### Starting Application Parts with Mount in Clojure Source: https://github.com/tolitius/mount/blob/master/doc/differences-from-component.md This snippet demonstrates how to start specific parts of an application using Mount, targeting states within particular namespaces. It shows the command to start states and the expected output indicating the startup process. ```Clojure (mount/start #'app.config/app-config #'app.nyse/conn) ``` -------------------------------- ### Defining and Starting a State in Clojure REPL Source: https://github.com/tolitius/mount/blob/master/README.md This code demonstrates defining a state `won't-be-here-long` with `:start` and `:stop` functions, and then starting it using `mount/start`. It shows the output when the state is successfully started. ```Clojure dev=> (defstate won't-be-here-long :start (println "I am starting... ") :stop (println "I am stopping... ")) #'dev/won't-be-here-long dev=> dev=> (mount/start #'dev/won't-be-here-long) INFO app.utils.logging - >> starting.. #'dev/won't-be-here-long I am starting... {:started ["#'dev/won't-be-here-long"]} dev=> ``` -------------------------------- ### Composing States with `only`, `with-args`, `except`, `swap-states`, and `swap` in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates a more involved example of composing states using `only`, `with-args`, `except`, `swap-states`, and `swap` functions from the Mount library. It starts with a set of states, passes runtime arguments, excludes certain states, swaps states with alternative start and stop functions, swaps states with new values, and then starts the resulting states. This allows for advanced customization of application startup behavior. ```clojure (-> (only #{#'foo/a #'foo/b #'foo/c #'bar/d #'baz/e}) (with-args {:a 42}) (except [#'foo/c #'bar/d]) (swap-states {#'foo/a {:start #(create-connection test-conf) :stop #(disconnect a)}}) (swap {#'baz/e {:datomic {:uri "datomic:mem://composable-mount"}}}) mount/start) ``` -------------------------------- ### Defining a simple state with a start function Source: https://github.com/tolitius/mount/blob/master/README.md This snippet shows how to define a state using `defstate` with only a `:start` function. The `create-conn` function is responsible for creating the connection. ```Clojure (defstate conn :start (create-conn)) ``` -------------------------------- ### Starting Mount with Arguments in -main Function (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet shows how to start a Mount application with runtime arguments passed to the `-main` function. The `mount/start-with-args` function is used to initialize the application with the provided arguments. The arguments are then available via `(mount/args)`. No dependencies are explicitly required beyond `mount` itself. ```Clojure (defn -main [& args] (mount/start-with-args args)) ``` -------------------------------- ### Defining a state with start and stop functions Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to define a state using `defstate`. It includes a `:start` function to create the state and a `:stop` function to clean up the state when it's reloaded or the application shuts down. `create-conn` and `disconnect` are assumed to be defined elsewhere. ```Clojure (defstate conn :start (create-conn) :stop (disconnect conn)) ``` -------------------------------- ### Starting an Application Without Certain States in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to start an application without certain states using the `mount/start-without` function. This is useful for excluding queue listeners or other components that are not needed during REPL time or testing, allowing for a more streamlined development experience. ```clojure (mount/start-without #'app.feeds/feed-listener #'app/nrepl) ``` -------------------------------- ### Swapping States with States using `start-with-states` Source: https://github.com/tolitius/mount/blob/master/README.md This snippet shows how to use `mount/start-with-states` to swap states with other states, providing `:start` and `:stop` functions for the substitutes. It replaces the `#'app.neo/db` and `#'app.neo/publisher` states with functions that connect to and create a test database and publisher, respectively. ```Clojure (mount/start-with-states {#'app.neo/db {:start #(connect test-config) :stop #(disconnect db)} #'app.neo/publisher {:start #(create-pub test-config) :stop #(close-pub publisher)}}) ``` -------------------------------- ### Application entry point with mount in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code shows an example of an application entry point namespace that requires other namespaces with `defstate` definitions and calls `mount/start` to ensure all states are initialized. This is important when packaging an application. ```Clojure (ns my.app (:require [a] [b] [c] [mount.core :as mount])) (defn rock-n-roll [] ;; or (defn -main [args].. ) (mount/start)) ``` -------------------------------- ### Starting and Stopping Specific States in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to start and stop specific states using the `mount/start` and `mount/stop` functions. By passing vars (prefixed with their namespaces) to these functions, you can control which states are activated or deactivated, allowing for focused testing and development. ```clojure (mount/start #'app.config/config #'app.nyse/conn) ... (mount/stop #'app.config/config #'app.nyse/conn) ``` -------------------------------- ### Defining a state with lazy start in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code defines a state called `db-connection` that will start lazily when it is dereferenced. The `:start` key defines the action to perform when the state starts, and the `:stop` key defines the action to perform when the state stops. ```Clojure (defstate db-connection :start (println "connecting") :stop (println "disconnecting...")) ``` -------------------------------- ### Entering REPL Environment Source: https://github.com/tolitius/mount/blob/master/README.md This command starts a REPL (Read-Eval-Print Loop) environment using Boot. It allows interactive execution of Clojure code. After starting the REPL, the namespace is switched to `(dev)` to access development-related functions. ```Shell $ boot repl ``` -------------------------------- ### Start Jetty Server with Mount State Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This Clojure code defines a function to start a Jetty server using the provided application configuration. It then defines a mount state `nyse-app` that starts the server and provides a stop function to shut it down. ```Clojure (defn start-nyse [{:keys [www]}] (-> (routes mount-example-routes) (handler/site) (run-jetty {:join? false :port (:port www)}))) (defstate nyse-app :start (start-nyse app-config) :stop (.stop nyse-app)) ;; it's a "org.eclipse.jetty.server.Server" at this point ``` -------------------------------- ### Defining State with Documentation String in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to define a state using `defstate` with an associated documentation string to describe its purpose. The `:start` key specifies the initial value of the state, which in this case is the result of adding 1 and 41. ```Clojure (defstate answer "answer to the ultimate question of life universe and everything" :start (+ 1 41)) ``` -------------------------------- ### Define Main Entry Point Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This Clojure code defines the main entry point for the application, which simply starts the mount states. ```Clojure (defn -main [& args] (mount/start)) ``` -------------------------------- ### Accessing a state that throws on lazy start in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code demonstrates how dereferencing a state with `^{:on-lazy-start :throw}` metadata before it is started results in a `RuntimeException`. The state can be started explicitly using `mount/start`. ```Clojure => @db-connection ;; this will throw since db connection is deref'ed before it was started java.lang.RuntimeException: :on-lazy-start is set to :throw i.e. (defstate {:on-lazy-start :throw} #'dev/db-connection...) and #'dev/db-connection state was not explicitly started before it was deref'ed (i.e. @#'dev/db-connection) => (mount/start #'dev/db-connection) connecting {:started ["#'dev/db-connection"]} => @db-connection 42 ``` -------------------------------- ### Defining Config State in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet defines a `config` state using `defstate` and loads configuration from a file using the `load-config` function. The `:start` key specifies the function to be called to initialize the state. ```Clojure (ns app.config (:require [mount.core :refer [defstate]])) (defstate config :start (load-config "test/resources/config.edn")) ``` -------------------------------- ### Accessing a lazily started state in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code demonstrates how a state defined with lazy start is automatically started when it is dereferenced using `@`. The `mount/running-states` function shows the currently running states. ```Clojure => (mount/in-cljc-mode) :cljc => (defstate db-connection :start (println "connecting") :stop (println "disconnecting...")) => db-connection #object[mount.core.DerefableState 0x546b9d51 {:status :pending, :val nil}] dev=> (mount/running-states) #{} dev=> @db-connection ;; db-connection will start here when deref'ed even though it was not started explicitly connecting dev=> (mount/running-states) #{"#'dev/db-connection"} ``` -------------------------------- ### Composing States with `only`, `except`, and `with-args` in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to compose states using `only`, `except`, and `with-args` functions from the Mount library. It starts with a set of states, excludes certain states, passes runtime arguments, and then starts the remaining states. This allows for fine-grained control over which states are active during application startup. ```clojure (-> (only #{#'foo/a #'foo/b #'foo/c #'bar/d #'baz/e}) (except [#'foo/c #'bar/d]) (with-args {:a 42}) mount/start) ``` -------------------------------- ### Checking out with-args Branch Source: https://github.com/tolitius/mount/blob/master/README.md This bash command checks out the `with-args` branch in git. This branch contains an example app that takes command line parameters. ```Clojure git checkout with-args ``` -------------------------------- ### Defining State with a Scalar Value in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates defining a state with a simple scalar value as its initial value. The `:start` key is assigned the value 42. ```Clojure (defstate answer-to-the-ultimate-question-of-life-the-universe-and-everything :start 42) ``` -------------------------------- ### Deleting a State and Starting All States in Clojure REPL Source: https://github.com/tolitius/mount/blob/master/README.md This code demonstrates deleting a state `won't-be-here-long` using `ns-unmap` and then starting all states using `mount/start`. Mount detects the deletion and stops the state, invoking its `:stop` function. ```Clojure dev=> (ns-unmap 'dev 'won't-be-here-long) nil dev=> (mount/start) "<< stopping.. #'dev/won't-be-here-long (it was deleted)" I am stopping... INFO app.utils.logging - >> starting.. #'app.conf/config INFO app.utils.logging - >> starting.. #'app.db/conn INFO app.utils.logging - >> starting.. #'app.www/nyse-app INFO app.utils.logging - >> starting.. #'app.example/nrepl {:started ["#'app.conf/config" "#'app.db/conn" "#'app.www/nyse-app" "#'app.example/nrepl"]} ``` -------------------------------- ### Defining a state that throws on lazy start in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code defines a state called `db-connection` that throws an exception if it is dereferenced before it is explicitly started. The `^{:on-lazy-start :throw}` metadata is used to enable this behavior. ```Clojure (defstate ^{:on-lazy-start :throw} db-connection :start (do (println "connecting") 42) :stop (println "disconnecting...")) ``` -------------------------------- ### Checking out Uberjar Branch Source: https://github.com/tolitius/mount/blob/master/README.md This bash command checks out the `uberjar` branch in git. This branch contains an example webapp and its uberjar sibling. ```Clojure git checkout uberjar ``` -------------------------------- ### Parsing Arguments Before Starting Mount (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet demonstrates parsing arguments before passing them to `mount/start-with-args`. This allows for preprocessing or validation of the arguments before they are used by the application. The `parse-args` function is assumed to be application-specific and handles the argument parsing logic. Requires a `parse-args` function to be defined. ```Clojure (defn -main [& args] (mount/start-with-args (parse-args args))) ``` -------------------------------- ### Defining States with Various Value Types in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet showcases defining states with different types of values for the `:start` key, including scalar values, anonymous functions, partial functions, and function references. It demonstrates the flexibility of mount in handling various initialization scenarios. ```Clojure (defn f [n] (fn [m] (+ n m))) (defn g [a b] (+ a b)) (defn- pf [n] (+ 41 n)) (defn fna [] 42) (defstate scalar :start 42) (defstate fun :start #(inc 41)) (defstate with-fun :start (inc 41)) (defstate with-partial :start (partial g 41)) (defstate f-in-f :start (f 41)) (defstate f-no-args-value :start (fna)) (defstate f-no-args :start fna) (defstate f-args :start g) (defstate f-value :start (g 41 1)) (defstate private-f :start pf) ``` -------------------------------- ### Running a Clojure Uberjar Application Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This command executes the standalone JAR file created in the previous step using the Java runtime. It starts the web application, making it accessible on the specified port. ```Bash $ java -jar target/mount-0.1.5-SNAPSHOT-standalone.jar ``` -------------------------------- ### Checkout Uberjar Branch Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This bash command checks out the 'uberjar' branch in git, allowing you to follow along with the example. ```Bash $ git checkout uberjar Switched to branch 'uberjar' ``` -------------------------------- ### Using mount-up to monitor state changes in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to use the mount-up library to monitor the up and down events of Mount's states. It requires the mount-up.core and mount libraries. It logs information about the starting and stopping of states. ```Clojure => (require '[mount-up.core :as mu]) => (mu/on-upndown :info mu/log :before) => (mount/start) INFO mount-up.core - >> starting.. #'boot.user/server {:started ["#'boot.user/server"]} => (mount/stop) INFO mount-up.core - << stopping.. #'boot.user/server {:stopped ["#'boot.user/server"]} ``` -------------------------------- ### Defining State with Mount in Clojure Source: https://github.com/tolitius/mount/blob/master/doc/differences-from-component.md This snippet illustrates the concise syntax for defining application state using Mount's `defstate` macro. It highlights the minimal boilerplate required compared to Component, focusing on the state name, start function, and stop function. ```Clojure (defstate name :start fn :stop fn) ``` -------------------------------- ### Define Mount Routes Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This Clojure code defines the routes for the mount example application using the `defroutes` macro. It includes routes for the root path, retrieving orders by ticker, and adding new orders. ```Clojure (defroutes mount-example-routes (GET "/" [] "welcome to mount sample app!") (GET "/nyse/orders/:ticker" [ticker] (generate-string (find-orders ticker))) (POST "/nyse/orders" [ticker qty bid offer] (add-order ticker (bigdec bid) (bigdec offer) (Integer/parseInt qty)) (generate-string {:added {:ticker ticker :qty qty :bid bid :offer offer}}))) ``` -------------------------------- ### Stopping mount and getting affected states in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This Clojure code demonstrates how `mount/stop` returns a map containing a vector of the states that were stopped, in the order they were affected. ```Clojure dev=> (mount/stop) {:stopped [#'app/nrepl #'app.nyse/conn #'app.config/config]} ``` -------------------------------- ### Defining Reset Function for Application Reloading in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet defines a `reset` function that stops the application, refreshes the namespaces using `tools.namespace`, and then starts the application again. This function is used in the REPL to reload the application state with namespace refreshing. ```Clojure (defn go [] (start) :ready) (defn reset [] (stop) (tn/refresh :after 'dev/go)) ``` -------------------------------- ### Defining State with defstate in ClojureScript Source: https://github.com/tolitius/mount/blob/master/doc/clojurescript.md This snippet demonstrates how to define a state using the `defstate` macro from the `mount.core` library. It defines a state called `system-a` that connects to a URI from the config when started and disconnects when stopped. The config is dereferenced using `@config` to access its current state. ```ClojureScript (ns app.websockets (:require [app.conf :refer [config]] [app.audit-log :refer [audit log]]) (:require-macros [mount.core :refer [defstate]])) ;; ... (defstate system-a :start (connect (get-in @config [:system-a :uri])) :stop (disconnect system-a)) ``` -------------------------------- ### Accessing Arguments within a Function (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet shows how to access runtime arguments within a regular function using `(mount/args)`. The example checks for a `:help` argument and prints a help message if it is present. Requires `mount` and application-specific `info` function. ```Clojure (defn load-config [path] ;; ... (if (:help (mount/args)) (info "\n\nthis is a sample mount app to demo how to pass and read runtime arguments\n")) ;; ...) ``` -------------------------------- ### Stopping All States Except Specified States using `stop-except` Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to use `mount/stop-except` to stop all application states except for the specified ones. In this example, it stops all states except `#'app.www/nyse-app`, allowing the application to be restarted without bringing down the specified state. ```Clojure (mount/stop-except #'app.www/nyse-app) ``` -------------------------------- ### Restarting a Web Server with Mount Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to restart a web server using the `mount/start` function. It takes a var representing the web application as an argument. After restarting, the server should be accessible again. ```Clojure (mount/start #'app.www/nyse-app) ``` -------------------------------- ### Swapping State with a Value using `start-with` Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to swap the `send-sms` state with a test function using `mount/start-with`. It creates a core.async channel and a function that sends SMS messages to the channel. The `start-with` function replaces the original `send-sms` state with this test function. ```Clojure (let [sms-ch (chan) send-sms (fn [sms] (go (>! sms-ch sms)))] (mount/start-with {#'app.sms/send-sms send-sms}) ;; <<<< swapping the "send-sms" state with a test function ;; testing.. checking "sms-ch" channel (mount/stop)) ``` -------------------------------- ### Configure Uberjar Settings Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This Clojure code shows the configuration settings in `project.clj` for building an uberjar. It specifies the source paths, the main entry point, and enables ahead-of-time compilation. ```Clojure :uberjar {:source-paths ["test/app"] :main app :aot :all}} ``` -------------------------------- ### Parsing Arguments with tools.cli (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet demonstrates parsing command-line arguments using `clojure.tools.cli`. It defines a `parse-args` function that uses `parse-opts` to parse arguments based on a predefined options table. The parsed options are then returned. Requires `clojure.tools.cli` as a dependency. ```Clojure (defn parse-args [args] (let [opts [["-d" "--datomic-uri [datomic url]" "Datomic URL" :default "datomic:mem://mount"] ["-h" "--help"]]] (-> (parse-opts args opts) :options))) ``` -------------------------------- ### Defining Database Connection State in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This snippet defines a `conn` state that depends on the `config` state from the `app.config` namespace. It uses the `create-connection` function to establish a database connection, passing the `config` as an argument. ```Clojure (ns app.database (:require [mount.core :refer [defstate]] [app.config :refer [config]])) (defstate conn :start (create-connection config)) ``` -------------------------------- ### Switching to the Development Namespace Source: https://github.com/tolitius/mount/blob/master/README.md This command switches the current namespace to `dev`. This namespace likely contains development-specific functions and configurations for the application. It's essential for accessing functions like `reset`. ```Clojure (dev) ``` -------------------------------- ### Verifying Web Server is Running Source: https://github.com/tolitius/mount/blob/master/README.md This bash command attempts to connect to the web server on localhost port 4242. The expected output is a welcome message, confirming that the server has been successfully restarted. ```Clojure curl localhost:4242 ``` -------------------------------- ### Packaging a Clojure Project into an Uberjar with Leiningen Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This command uses Leiningen to clean the project and create a standalone JAR file (uberjar) containing all dependencies. The resulting JAR file is placed in the target directory. ```Clojure $ lein do clean, uberjar ``` -------------------------------- ### Requiring mount.core namespace Source: https://github.com/tolitius/mount/blob/master/README.md This snippet shows how to require the `mount.core` namespace and refer to the `defstate` macro, which is used to define application state. ```Clojure (require '[mount.core :refer [defstate]]) ``` -------------------------------- ### Reloading Application State in Clojure REPL Source: https://github.com/tolitius/mount/blob/master/README.md This snippet shows how to reload the application state in a Clojure REPL using `mount/stop` and `mount/start`. This allows for restarting the application without restarting the REPL itself. ```Clojure (require '[mount.core :as mount]) (mount/stop) (mount/start) ``` -------------------------------- ### Define a State with `defstate` Source: https://github.com/tolitius/mount/blob/master/README.md This snippet defines a state called `send-sms` using `defstate` from the `mount.core` namespace. It initializes the state with the result of calling `create-sms-sender` with the `:sms` configuration. ```Clojure (ns app.sms) ;; ... (defstate send-sms :start (create-sms-sender (:sms config))) ``` -------------------------------- ### Finding Orders After Adding Post-Reset Source: https://github.com/tolitius/mount/blob/master/README.md The `find-orders` function retrieves orders from the simulated stock exchange based on the ticker symbol after adding an order post-reset. It takes a connection object (`conn`) and a ticker symbol as input. The function returns a list of maps, where each map represents an order matching the specified ticker symbol. ```Clojure (find-orders conn "TSLA") ``` -------------------------------- ### Adding Orders After Reset Source: https://github.com/tolitius/mount/blob/master/README.md The `add-order` function adds a new order to the simulated stock exchange after the application has been reset. It takes a connection object (`conn`) and a map containing order details such as ticker symbol, bid price, offer price, and quantity. This demonstrates adding orders after a clean state. ```Clojure (add-order conn {:ticker "TSLA" :bid 232.381M :offer 232.436M :qty 250}) ``` -------------------------------- ### Referencing a state from another namespace Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to require a state (e.g., `conn`) defined in another namespace (`above`) and use it within the current namespace (`app`). ```Clojure (ns app (:require [above :refer [conn]])) ``` -------------------------------- ### Stopping a Web Server with Mount Source: https://github.com/tolitius/mount/blob/master/README.md This snippet demonstrates how to stop a web server using the `mount/stop` function. It takes a var representing the web application as an argument. After stopping, a curl command verifies that the server is no longer accessible. ```Clojure (mount/stop #'app.www/nyse-app) ``` -------------------------------- ### Resetting Application State Source: https://github.com/tolitius/mount/blob/master/README.md The `reset` function stops all components, reloads namespaces, and restarts all components. This is useful for applying code changes or returning the application to a clean state. It ensures that all dependencies and configurations are reloaded. ```Clojure (reset) ``` -------------------------------- ### Extracting State Dependencies with states-with-deps Source: https://github.com/tolitius/mount/blob/master/doc/differences-from-component.md This Clojure code snippet demonstrates how to extract state dependencies using the `states-with-deps` function from the `mount.tools.graph` namespace. It requires the `mount.tools.graph` namespace and returns a list of maps, each representing a state with its dependencies, order, and status. The output shows the dependencies between different parts of an application, such as configuration, database connection, web application, and nREPL. ```Clojure (require '[mount.tools.graph :as graph]) (graph/states-with-deps) ``` ```Clojure ({:name "#'app.conf/config", :order 1, :status #{:started}, :deps #{}} {:name "#'app.db/conn", :order 2, :status #{:started}, :deps #{"#'app.conf/config"}} {:name "#'app.www/nyse-app", :order 3, :status #{:started}, :deps #{"#'app.conf/config"}} {:name "#'app.example/nrepl", :order 4, :status #{:started}, :deps #{"#'app.www/nyse-app" "#'app.conf/config"}}) ``` -------------------------------- ### Adding Orders via HTTP POST Request Source: https://github.com/tolitius/mount/blob/master/README.md This command sends an HTTP POST request to add a new order to the simulated stock exchange. It uses `curl` to send the request with order details in the request body. The server responds with a JSON object confirming the order was added. ```Shell $ curl -X POST -d "ticker=TSLA&qty=100&bid=232.38&offer=232.43" "http://localhost:4242/nyse/orders" ``` -------------------------------- ### Finding Orders in the Exchange Source: https://github.com/tolitius/mount/blob/master/README.md The `find-orders` function retrieves orders from the simulated stock exchange based on the ticker symbol. It takes a connection object (`conn`) and a ticker symbol as input. The function returns a list of maps, where each map represents an order matching the specified ticker symbol. ```Clojure (find-orders conn "GOOG") ``` -------------------------------- ### Finding Orders After Reset Source: https://github.com/tolitius/mount/blob/master/README.md This command retrieves orders from the simulated stock exchange based on the ticker symbol after resetting the application state. It takes a connection object (`conn`) and a ticker symbol as input. The function returns an empty list because the database is reset. ```Clojure (find-orders conn "GOOG") (find-orders conn "TSLA") ``` -------------------------------- ### Accessing Arguments within a defstate (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet demonstrates accessing runtime arguments within a `defstate` definition. The `(mount/args)` function is used to retrieve the arguments and pass them to the `new-connection` and `disconnect` functions. Requires `mount` and application-specific `new-connection` and `disconnect` functions. ```Clojure (defstate conn :start (new-connection (mount/args)) :stop (disconnect (mount/args) conn)) ``` -------------------------------- ### Verifying Web Server is Stopped Source: https://github.com/tolitius/mount/blob/master/README.md This bash command attempts to connect to the web server on localhost port 4242. The expected output is a connection refused error, confirming that the server has been successfully stopped. ```Bash curl localhost:4242 ``` -------------------------------- ### Querying Data While Web Server is Stopped Source: https://github.com/tolitius/mount/blob/master/README.md This snippet shows that other parts of the application, such as database queries, continue to function even when the web server is stopped. It uses a `find-orders` function to retrieve order data. ```Clojure (find-orders conn "TSLA") ``` -------------------------------- ### Finding Orders After HTTP Post Source: https://github.com/tolitius/mount/blob/master/README.md This command retrieves orders from the simulated stock exchange based on the ticker symbol after adding an order via HTTP POST request. It takes a connection object (`conn`) and a ticker symbol as input. The function returns a list of maps, where each map represents an order matching the specified ticker symbol. ```Clojure (find-orders conn "TSLA") ``` -------------------------------- ### Defining State with :on-reload :noop in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This code defines a state called `mem-db` with `:on-reload` set to `:noop`. This configuration prevents the state from being restarted or stopped upon namespace recompilation, but it will still respond to `mount/start` and `mount/stop` calls. ```Clojure (defstate ^{:on-reload :noop} mem-db :start (connect config) :stop (disconnect mem-db)) ``` -------------------------------- ### Adding Orders to the Exchange Source: https://github.com/tolitius/mount/blob/master/README.md The `add-order` function adds a new order to the simulated stock exchange. It takes a connection object (`conn`) and a map containing order details such as ticker symbol, bid price, offer price, and quantity. This function interacts with the underlying data store to persist the order. ```Clojure (add-order conn {:ticker "GOOG" :bid 665.51M :offer 665.59M :qty 100}) (add-order conn {:ticker "GOOG" :bid 665.50M :offer 665.58M :qty 300}) ``` -------------------------------- ### Defining State with :on-reload :stop in Clojure Source: https://github.com/tolitius/mount/blob/master/README.md This code defines a state called `mem-db` with `:on-reload` set to `:stop`. This configuration ensures that the state is stopped but not restarted upon namespace recompilation. ```Clojure (defstate ^{:on-reload :stop} mem-db :start (connect config) :stop (disconnect mem-db)) ``` -------------------------------- ### Accessing Runtime Arguments (Clojure) Source: https://github.com/tolitius/mount/blob/master/doc/runtime-arguments.md This snippet shows how to access the runtime arguments passed to the application using `(mount/args)`. This function returns the original arguments passed to `-main`, unless they have been parsed or modified. No dependencies are explicitly required beyond `mount` itself. ```Clojure (mount/args) ``` -------------------------------- ### Switching Mount to Clojure/ClojureScript Mode (cljc) Source: https://github.com/tolitius/mount/blob/master/doc/clojurescript.md This code snippet demonstrates how to switch the Mount library into 'cljc' mode, which supports both Clojure and ClojureScript. This mode requires states to be dereferenced using `@`. ```Clojure (mount/in-cljc-mode) ``` -------------------------------- ### Submitting Data to a REST Endpoint using cURL Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This command uses cURL to send a POST request to a REST endpoint, simulating an order placement. The data is sent in the request body as a string of key-value pairs. ```Clojure $ curl -X POST -d "ticker=GOOG&qty=100&bid=665.51&offer=665.59" "http://localhost:4242/nyse/orders" ``` -------------------------------- ### Stop Application Except Certain States Source: https://github.com/tolitius/mount/blob/master/doc/uberjar.md This Clojure code defines a function to stop the application, excluding the `nyse-app` state. This prevents the web server from being restarted during development, avoiding potential `java.net.BindException` errors. ```Clojure (defn stop [] (mount/stop-except #'app.www/nyse-app)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.