This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-18
Channels
- # admin-announcements (1)
- # beginners (4)
- # boot (18)
- # cider (4)
- # cljsrn (17)
- # clojure (77)
- # clojure-austin (6)
- # clojure-greece (6)
- # clojure-spec (81)
- # clojure-uk (6)
- # clojurescript (32)
- # code-art (2)
- # core-async (12)
- # cursive (1)
- # datomic (1)
- # emacs (15)
- # funcool (1)
- # hoplon (108)
- # om (9)
- # onyx (83)
- # planck (1)
- # re-frame (3)
- # reagent (4)
- # specter (6)
- # spirituality-ethics (4)
- # yada (9)
i haven’t gotten to the bottom of the issue, but i suspect that this, combined with some unit tests that use the page macro where everything gets implicitly added to that namespace might have something to do with it
object is going to be global in any cljs namespace, shouldn’t it be a reserved symbol?
i mean it hasn't been an issue so far, until we added something that adds a protocol to object
in that namespace
if you add the protocol to the fully qualified name of the thing it would be fine i think
any of those lowercase clojurescript types that correspond to js/Object
, js/String
, js/Number
, etc i would imagine should be reserved.
it warn’s that you are extending a javascript type, and prompts you to use, say string lowercase, instead.
WARNING: Extending an existing JavaScript type - use a different symbol name instead of js/Object e.g object at line 76 /Users/jumblerg/.boot/cache/tmp/Users/jumblerg/Development/libs/hoplon/4tx/-rcsl8f/hoplon/core.cljs
WARNING: Extending an existing JavaScript type - use a different symbol name instead of js/String e.g string at line 81 /Users/jumblerg/.boot/cache/tmp/Users/jumblerg/Development/libs/hoplon/4tx/-rcsl8f/hoplon/core.cljs
WARNING: Extending an existing JavaScript type - use a different symbol name instead of js/Number e.g number at line 86 /Users/jumblerg/.boot/cache/tmp/Users/jumblerg/Development/libs/hoplon/4tx/-rcsl8f/hoplon/core.cljs
i’m trying to figure out where they are actually defined in the source, suspect these conventions have something to do with the closure compiler
incidentally, extending the js/Types has always worked for me in practice; the compiler just complains
@jumblerg @micha please correct me if im wrong but do you want to be extending the entire js/Type? When extending types for firebase-cljs i has to use Type
without the js/
as to not add functions to the entire global type.
https://github.com/degree9/firebase-cljs/blob/master/src/firebase_cljs/auth.cljs#L96
It was my understanding that using js/Object
would modify the Object
prototype
@flyboarder: do you have suggested reading on this subject?
@jumblerg: im looking for it, should be in my history somewhere I came across this issue last week 😛
initially i was extending the js/Node
, but ie 8 doesn’t have, or at least expose, the Node type
so i simply put it on object
, which is the equivalent of saying, if there’s not a more concrete implementation provided, call this general implementation instead.
@flyboarder: ah, many thanks! this is exactly the explanation i was looking for, the difference between, say js/Object
and object
was a bit unclear to me.
yeah it’s still a bit fuzzy which i why I was asking 🙂
yes so that may be what you want in some cases but I doubt it should be generally used in a library where you dont know what could exist at runtime
But in hoplon case im not sure how it should go
in our case, it is done correctly by extending object
, string
, number
, etc; we’re not modifying the prototype
awesome, on same page now i believe 🙂
micha extended the Element prototype, for example, so that other libraries could call, say .addChild(<someelement>)
and remain compatible with hoplon’s model
but i thought thats exactly what using the js/<Type>
variant does was modify the prototype
corrected^
the reason for extending object
, istead of js/Object
according to dnolen, is for optimization reasons
“”"It's not safe to change the JavaScript base types directly - besides the obvious down sides of global changes to types you don't control, this often triggers dramatic de-optimization in JavaScript engines.””"
lol group learning moment
hmmm i guess this means i can extend object
for dynamic types that only exist at runtime
i'm guessing it would include a check for (satisfies? IFoo x)
and then dispatch on type in a case analysis?
i’ll check in a moment, running more ie 8 tests atm with the dev tools stripped out of the pipline
neat little fn i just made: https://gist.github.com/2355d19343c693c853fe20f2f762307b
@dnolen: thanks for chiming in. i keep reading as much, but do you have a concrete example in mind?
…and we’ve established now, with a bit of research, that extending a js/<Type> does in fact modify the corresponding prototype
@dnolen: where are the corresponding lowercase types used by clojurescript introduced into the source?
i guess i wasn’t clear in my question, i mean the definitions of the lowercase types themselves. i mean, i can extend object
with no optimizations; where is object
, as opposed to js/Object
, introduced?
we do this for all the native JS types - it’s a syntax thing handled by the deftype
style macros
no worries. the semantics of things become a lot clearer when i can step through the source.
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/core.cljc#L1208
extend-type
macro is the thing to look at which all the deftype
style macros will emit
@dnolen: much appreciate the clarity!