This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-15
Channels
- # adventofcode (39)
- # aws (1)
- # beginners (39)
- # boot (1)
- # calva (79)
- # cider (8)
- # cljdoc (13)
- # cljs-dev (45)
- # clojure (89)
- # clojure-berlin (2)
- # clojure-europe (1)
- # clojure-uk (1)
- # clojurescript (7)
- # datomic (1)
- # emacs (6)
- # figwheel-main (2)
- # fulcro (29)
- # hyperfiddle (21)
- # juxt (1)
- # leiningen (1)
- # lumo (3)
- # music (1)
- # off-topic (20)
- # pedestal (23)
- # portkey (3)
- # reagent (2)
- # rum (1)
- # shadow-cljs (27)
- # vim (5)
Welcome! Thanks for making the process easy. I am having fun playing with the new protocols now
Well, now that I’m in your good graces 😛 I’ll ask a question. I’ve hit a kind of corner case using with-meta
with functions… and React. The problem:
(defn Foo [_] "bar")
(react-is/isValidElementType Foo)
;; => true
(react-is/isValidElementType (with-meta Foo {:bar "baz"}))
;; => false
The crux of the issue seems to be that React checks if typeof
equals "function"
.
(goog/typeOf Foo)
;; => "function"
(goog/typeOf (with-meta Foo {:bar "baz"}))
;; => "object"
there happens to be another issue already filed about with-meta
and functions, CLJS-2446: https://dev.clojure.org/jira/browse/CLJS-2446
the proposed implementation in the ticket actually solves this particular thing as well
mfikes actually pasted a similar idea at me the other day: https://gist.github.com/mfikes/122814757fd1f2aec9de509446793e5f
WeakMap would be better in that it wouldn’t leak memory as the metas
map is accreted and the referenced objects are GC’d, but I’d be worried about support in all environments 😕
I'm not sure that impl is accreting/leaking though. New references are bumping off the old ones from the map, right?
You could also cram the meta in the object: https://gist.github.com/mfikes/122814757fd1f2aec9de509446793e5f#gistcomment-2786227
I was just wondering about that 😁 it's just JavaScript. How would that fair with advanced compile?
Interesting question. If you did (set! (.-object-meta o) meta)
then your key could get smaller, but maybe collide with another existing key.
I think there’s a typo on this line: https://github.com/Lokeh/clojurescript/blob/6ccb629e365f46a9516e4defeced652cce9d4d35/src/main/cljs/cljs/repl.cljs#L121
For reference, here is the original source that was ported https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L211
I'm not seeing the typo @lilactown. Grabbing another cup of coffee. 🙂
Yeah, they probably should be symbols. Perhaps there is an older destructuring fn at play that is causing the issue. Both can work.
cljs.user=> (let [{:foo/keys [:a]} {:foo/a 1}] a)
1
cljs.user=> (let [{:foo/keys [a]} {:foo/a 1}] a)
1
I thought I uncovered another problem with MetaFn: it breaks equality
(= Foo (with-meta Foo {:bar "baz"}))
but apparently Clojure has the same behavior 😐
user=> (defn foo [] "bar")
#'user/foo
user=> (= foo (with-meta foo {:bar "baz"}))
false
@lilactown You are right about the :foo/keys
thing. In that case, the spec says the vector has to contain simple symbols. https://github.com/clojure/core.specs.alpha/blob/master/src/main/clojure/clojure/core/specs/alpha.clj#L37
Now that master provides the JavaScript error type when an execution error occurs, as in
cljs.user=> (ffirst 1)
Execution error (Error) at (<cljs repl>:1).
1 is not ISeqable
there might be more motivation to revise the places where we simply throw js/Error
and instead throw more specific error types.
For example, note the appearance of TypeError
:
cljs.user=> (re-matches #"a" 1)
Execution error (TypeError) at (<cljs repl>:1).
re-matches must match against a string.
created an issue about metadata on functions and typeof
: https://dev.clojure.org/jira/browse/CLJS-3018
hope I’m being helpful 😬 I’d like this to work so I can figure out datafying React elements and components
OK I have no idea why, but now tests in master don’t run for me 😞
Exception in thread "main" clojure.lang.ExceptionInfo: failed compiling file:/Users/will/Code/clojurescript/src/test/cljs/cljs/npm_deps_test.cljs {:file #object[java.io.File 0x20843604 "/Users/will/Code/clojurescript/src/test/cljs/cljs/npm_deps_test.cljs"], :clojure.error/phase :compilation}, compiling:(/Users/will/Code/clojurescript/bin/../bin/cljsc.clj:22:1)
...
Caused by: clojure.lang.ExceptionInfo: No such namespace: lodash/array, could not locate lodash_SLASH_array.cljs, lodash_SLASH_array.cljc, or JavaScript source providing "lodash/array" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file /Users/will/Code/clojurescript/src/test/cljs/cljs/npm_deps_test.cljs {:tag :cljs/analysis-error}
going back to previous commits doesn’t remedy this. I tried re-cloning the repo even, same issue@lilactown Seeing if I can repro locally... this has happened before, I think owing to a glitch in npm