Skip to content

Commit

Permalink
Use 'default' as base class in ClojureScript
Browse files Browse the repository at this point in the history
The Lifecycle protocol is extended to java.lang.Object in Clojure, which
makes it possible to use any type of object as a component, although
only maps and records can receive dependencies.

When Component was ported to ClojureScript, `object` was used as the
base class, but some entities in ClojureScript are not sub-types of
`object`, as reported by goog.typeOf. For example, functions have the
type `function`. This prevents non-object types from being used as
components.

See also:

[extend-type]: https://github.com/clojure/clojurescript/blob/cb3e8c295ad5ed1961e7db1d0b19674eb7f71a5c/src/main/clojure/cljs/core.cljc#L1544
[defprotocol]: https://github.com/clojure/clojurescript/blob/cb3e8c295ad5ed1961e7db1d0b19674eb7f71a5c/src/main/clojure/cljs/core.cljc#L1961
[native-satisfies?]: https://github.com/clojure/clojurescript/blob/cb3e8c295ad5ed1961e7db1d0b19674eb7f71a5c/src/main/cljs/cljs/core.cljs#L247
[goog.typeOf]: https://google.github.io/closure-library/api/goog.html#typeOf
  • Loading branch information
Stuart Sierra committed Dec 12, 2016
1 parent a1db84d commit 69e6285
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/stuartsierra/component.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

;; No-op implementation if one is not defined.
(extend-protocol Lifecycle
#?(:clj java.lang.Object :cljs object)
#?(:clj java.lang.Object :cljs default)
(start [this]
this)
(stop [this]
Expand Down

0 comments on commit 69e6285

Please sign in to comment.