Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use leaven Startable and Stoppable #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions httpkit/src/com/palletops/bakery/httpkit.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions jetty/src/com/palletops/bakery/jetty.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion local-storage-atom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 0 additions & 2 deletions om-root/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions om-root/src/com/palletops/bakery/om_root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down
2 changes: 1 addition & 1 deletion secretary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions secretary/src/com/palletops/bakery/secretary.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -30,9 +30,10 @@

(defrecord Routing
[history nav-fn]
ILifecycle
Startable
(start [_]
(start-routing! history))
Stoppable
(stop [_]
(start-routing! history)))

Expand Down
12 changes: 6 additions & 6 deletions sente/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions sente/src/clj/com/palletops/bakery/sente.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions sente/src/cljs/com/palletops/bakery/sente.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))

Expand All @@ -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)))

Expand Down
10 changes: 5 additions & 5 deletions weasel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions weasel/src/cljs/com/palletops/bakery/weasel.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down