Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
Currently, _IWithMeta_ is implemented for functions by wrapping the function in a _MetaFn_ type.

However, this breaks certain expectations about the _typeof_ of the meta-fied value:


(defn Foo [_] "bar")

(goog/typeOf Foo)
;; => "function"

(goog/typeOf (with-meta Foo {:bar "baz"}))
;; => "object"


The primary case when this is not ideal is when interoping with JS code that does checks using _typeof_, like React does:


(react-is/isValidElementType Foo)
;; => true

(react-is/isValidElementType (with-meta Foo {:bar "baz"}))
;; => false


Ideally, _with-meta_ would preserve the _typeof_ value when possible.

3 Answers

0 votes
by

Comment made by: lilactown

There's a separate issue about MetaFn's and varargs, https://dev.clojure.org/jira/browse/CLJS-2446, whose proposed implementation also solves this particular edge case.

0 votes
by

Comment made by: lilactown

Attached patch:

  • replaces MetaFn type with meta-fn helper that creates new fn
    with IMeta specify!'d on it.
  • Also fixes CLJS-2446: with-meta doesn't work for variable arguments functions
  • Adds tests for metadata and fns
0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-3018 (reported by lilactown)
...