From c6d5d81f9d2a5e650d7810fac53f3ff6469c6d00 Mon Sep 17 00:00:00 2001 From: Hugo Duncan Date: Mon, 8 Sep 2014 15:01:22 -0400 Subject: [PATCH] Update to use leaven Startable and Stoppable --- httpkit/src/com/palletops/bakery/httpkit.clj | 5 +++-- jetty/src/com/palletops/bakery/jetty.clj | 5 +++-- local-storage-atom/README.md | 2 +- .../src/com/palletops/bakery/local_storage_atom.cljs | 2 +- om-root/README.md | 2 -- om-root/src/com/palletops/bakery/om_root.cljs | 5 +++-- secretary/README.md | 2 +- secretary/src/com/palletops/bakery/secretary.cljs | 5 +++-- sente/README.md | 12 ++++++------ sente/src/clj/com/palletops/bakery/sente.clj | 5 +++-- sente/src/cljs/com/palletops/bakery/sente.cljs | 5 +++-- weasel/README.md | 10 +++++----- weasel/src/cljs/com/palletops/bakery/weasel.cljs | 5 +++-- 13 files changed, 35 insertions(+), 30 deletions(-) diff --git a/httpkit/src/com/palletops/bakery/httpkit.clj b/httpkit/src/com/palletops/bakery/httpkit.clj index e2215c0..34ee823 100644 --- a/httpkit/src/com/palletops/bakery/httpkit.clj +++ b/httpkit/src/com/palletops/bakery/httpkit.clj @@ -3,7 +3,7 @@ Provides an idempotent start and stop." (:require [com.palletops.api-builder.api :refer [defn-api]] - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [org.httpkit.server :as httpkit] [schema.core :as schema])) @@ -18,11 +18,12 @@ (defrecord Httpkit [config server handler stop-timeout] - ILifecycle + Startable (start [component] (if server component (assoc component :server (start handler config)))) + Stoppable (stop [component] (if server (do diff --git a/jetty/src/com/palletops/bakery/jetty.clj b/jetty/src/com/palletops/bakery/jetty.clj index 7df03c3..f7035dc 100644 --- a/jetty/src/com/palletops/bakery/jetty.clj +++ b/jetty/src/com/palletops/bakery/jetty.clj @@ -3,7 +3,7 @@ Provides an idempotent start and stop." (:require [com.palletops.api-builder.api :refer [defn-api]] - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [ring.adapter.jetty :as jetty] [schema.core :as schema])) @@ -17,11 +17,12 @@ (.stop server)) (defrecord Jetty [handler config server] - ILifecycle + Startable (start [component] (if server component (assoc component :server (start handler config)))) + Stoppable (stop [component] (if server (do diff --git a/local-storage-atom/README.md b/local-storage-atom/README.md index 2e21792..9d9275f 100644 --- a/local-storage-atom/README.md +++ b/local-storage-atom/README.md @@ -21,7 +21,7 @@ accepts two arguments with the following values: `key` : a keyword for the key to store the atom under in local storage. -The component does not implement the `ILifecycle` protocol. +The component does not implement the `Startable` and `Stoppable` protocols. ## License diff --git a/local-storage-atom/src/com/palletops/bakery/local_storage_atom.cljs b/local-storage-atom/src/com/palletops/bakery/local_storage_atom.cljs index 9e79b7e..3a4d400 100644 --- a/local-storage-atom/src/com/palletops/bakery/local_storage_atom.cljs +++ b/local-storage-atom/src/com/palletops/bakery/local_storage_atom.cljs @@ -10,7 +10,7 @@ (defn-api local-storage-atom "Return a component that is an atom backed by local storage (if supported). `default` is used to initialise the atom if it is not already in - local storage. The ILifecycle protocol is not implemented." + local storage. The Startable and Stoppable protocols are not implemented." {:sig [[schema/Any schema/Keyword :- (protocol IDeref)]]} [default key] (let [app-state-atom (atom default)] diff --git a/om-root/README.md b/om-root/README.md index 5ddbecb..8de861e 100644 --- a/om-root/README.md +++ b/om-root/README.md @@ -20,8 +20,6 @@ accepts two arguments with the following values: `key` : a keyword for the key to store the atom under in local storage. -The component does not implement the `ILifecycle` protocol. - ## License Copyright © 2014 Hugo Duncan diff --git a/om-root/src/com/palletops/bakery/om_root.cljs b/om-root/src/com/palletops/bakery/om_root.cljs index 8dbff83..6ac6779 100644 --- a/om-root/src/com/palletops/bakery/om_root.cljs +++ b/om-root/src/com/palletops/bakery/om_root.cljs @@ -3,14 +3,15 @@ (:require-macros [com.palletops.api-builder.api :refer [defn-api]]) (:require - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [om.core :as om :include-macros true] [schema.core :as schema])) (defrecord OmRoot [f value options] - ILifecycle + Startable (start [_] (om/root f value options)) + Stoppable (stop [_] (om/detach-root (:target options)))) diff --git a/secretary/README.md b/secretary/README.md index 1d5743f..ff9b35c 100644 --- a/secretary/README.md +++ b/secretary/README.md @@ -12,7 +12,7 @@ Add `[com.palletops/bakery-secretary "0.1.1-SNAPSHOT"]` to your The `com.palletops.bakery.secretary/secretary` function returns a [leaven][leaven] component that wires up google closure's `History` to secretary. -The component implements the `ILifecycle` protocol. +The component implements the `Startable` and `Stoppable` protocols. ## License diff --git a/secretary/src/com/palletops/bakery/secretary.cljs b/secretary/src/com/palletops/bakery/secretary.cljs index 5944075..ac4a1ce 100644 --- a/secretary/src/com/palletops/bakery/secretary.cljs +++ b/secretary/src/com/palletops/bakery/secretary.cljs @@ -3,7 +3,7 @@ (:require-macros [com.palletops.api-builder.api :refer [defn-api]]) (:require - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [goog.events :as events] [goog.history.EventType :as EventType] [secretary.core :as secretary :include-macros true]) @@ -30,9 +30,10 @@ (defrecord Routing [history nav-fn] - ILifecycle + Startable (start [_] (start-routing! history)) + Stoppable (stop [_] (start-routing! history))) diff --git a/sente/README.md b/sente/README.md index 919d946..9327e2a 100644 --- a/sente/README.md +++ b/sente/README.md @@ -29,15 +29,15 @@ takes a single map as argument with the following keys. ### Clojure Server -The component implements the `ILifecycle` protocol in an idempotent -fashion. The component has a `:routes` key that contains ring routes -for handling the ajax calls used by sente. These routes need to be -included in your applications http handler function. +The component implements the `Startable` and `Stoppable` protocols in +an idempotent fashion. The component has a `:routes` key that +contains ring routes for handling the ajax calls used by sente. These +routes need to be included in your applications http handler function. ### Clojurescript Client -The `ILifecycle` implementation will start and stop the client -connection. +The `Startable` and `Stoppable` implementations will start and stop +the client connection. ## License diff --git a/sente/src/clj/com/palletops/bakery/sente.clj b/sente/src/clj/com/palletops/bakery/sente.clj index b46aecd..09f514c 100644 --- a/sente/src/clj/com/palletops/bakery/sente.clj +++ b/sente/src/clj/com/palletops/bakery/sente.clj @@ -3,7 +3,7 @@ (:require [clojure.core.async :as async :refer [chan close! go-loop]] [com.palletops.api-builder.api :refer [defn-api]] - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [compojure.core :refer [GET POST routes]] [compojure.route :refer [resources]] [schema.core :as schema :refer [optional-key]] @@ -40,11 +40,12 @@ (defrecord Sente [config channel-socket router routes chan-sock-atom] - ILifecycle + Startable (start [component] (if channel-socket component (merge component (start config chan-sock-atom)))) + Stoppable (stop [component] (if channel-socket (do diff --git a/sente/src/cljs/com/palletops/bakery/sente.cljs b/sente/src/cljs/com/palletops/bakery/sente.cljs index 26654a9..ac0faff 100644 --- a/sente/src/cljs/com/palletops/bakery/sente.cljs +++ b/sente/src/cljs/com/palletops/bakery/sente.cljs @@ -5,7 +5,7 @@ [cljs.core.async.macros :refer [go-loop]]) (:require [cljs.core.async :refer [alts! chan close!]] - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [schema.core :as schema :refer [optional-key]] [taoensso.sente :as sente])) @@ -30,9 +30,10 @@ (defrecord Sente [channel-socket router handler path config async-send-fn] - ILifecycle + Startable (start [component] (start component)) + Stoppable (stop [component] (stop component))) diff --git a/weasel/README.md b/weasel/README.md index 5a14366..e757b5a 100644 --- a/weasel/README.md +++ b/weasel/README.md @@ -26,14 +26,14 @@ takes a single map as argument with the following keys. ### Clojure Server -The component does not implement the `ILifecycle` protocol. To start -the clojurescript repl you can call the zero argument function placed -on the component's `:start-repl!` key. +The component does not implement the `Startable` and `Stoppable` +protocols. To start the clojurescript repl you can call the zero +argument function placed on the component's `:start-repl!` key. ### Clojurescript Client -The `ILifecycle` implementation will start and stop the client -connection. +The `Startable` and `Stoppable` implementations will start and stop +the client connection. ## License diff --git a/weasel/src/cljs/com/palletops/bakery/weasel.cljs b/weasel/src/cljs/com/palletops/bakery/weasel.cljs index 64b4c8c..c562286 100644 --- a/weasel/src/cljs/com/palletops/bakery/weasel.cljs +++ b/weasel/src/cljs/com/palletops/bakery/weasel.cljs @@ -3,17 +3,18 @@ (:require-macros [com.palletops.api-builder.api :refer [defn-api]]) (:require - [com.palletops.leaven.protocols :refer [ILifecycle]] + [com.palletops.leaven.protocols :refer [Startable Stoppable]] [schema.core :as schema] [weasel.repl :as weasel] [weasel.impls.websocket :as ws])) (defrecord Weasel [config] - ILifecycle + Startable (start [component] (when-not (weasel/alive?) (weasel/connect (str "ws://" (:host config) ":" (:port config)))) component) + Stoppable (stop [component] (when-let [connection @(weasel/ws-connection)] (ws/close connection)