Fork me on GitHub
#hoplon
<
2015-08-20
>
alandipert01:08:45

features retained-mode objects (dom) and system of constraints (cells)

alandipert01:08:31

i think "interactors" are analagous to browser events

onetom03:08:23

we have this initialization code for an external library:

function __ldinsp() {
        var insp = document.createElement('script');
        insp.type = 'text/javascript';
        insp.async = true;
        insp.id = "inspsync";
        insp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://cdn.inspectlet.com/inspectlet.js';
        var x = document.getElementsByTagName('script')[0];
        x.parentNode.insertBefore(insp, x);
    };
    document.readyState != "complete"
      ? (window.attachEvent
           ? window.attachEvent('onload', __ldinsp)
           : window.addEventListener('load', __ldinsp, false))
      : __ldinsp();

onetom03:08:59

it is doing this doc readyStater complete check and attaching onload/load events.

onetom03:08:08

i haven't really found anything in hoplon source which does anything like that

onetom03:08:28

i was wondering what's the "correct way" to integrate with such a libarary

alandipert03:08:44

wow, inspectlet looks great!

alandipert03:08:53

@onetom: dunno if it's "correct", but i'd probably port ldinsp to cljs and then call it via with-init

alandipert03:08:23

i believe with-init is what the last 5 lines of that snippet are roughly doing

onetom03:08:26

alandipert: micha just said the other day that with-init is probably not even necessary anymore in hoplon6

onetom03:08:53

we can just use a (timeout ...) instead, but that doesnt really work

onetom03:08:30

the function defined by this snippet is not defined yet when we are trying to call it from the (timeout #(...))

onetom03:08:20

why are we so behind on jquery versions, btw?

micha03:08:58

they changed some things in the 2.0 versions

micha03:08:45

the snippet you show will have issues with the parent.insertBefore business

micha03:08:20

does it need to create the script tag that way by fishing around in the dom?

micha03:08:02

can you just make the script tag yourself?

alandipert03:08:39

(defn load-inspectlet! []
  (let [insp (script :id "inspsync"
                     :type "text/javascript"
                     :src (str "http"
                               (if (= (-> js/document .-location .-protocol) "https:") "s")
                               "://cdn.inspectlet.com/inspectlet.js"))]
    (js* "window.__insp = {loaded: null}")
    (.appendChild (aget (.getElementsByTagName js/document "head") 0) insp)))

(js/jQuery load-inspectlet!)

alandipert03:08:27

i'm not sure about the browser support of adding stuff to head, works in chrome for me tho

micha03:08:54

@alandipert: in hoplon app?

micha03:08:04

sweet, unexpected

micha03:08:18

i haven't implemented insertBefore yet

alandipert03:08:20

dom + jquery, it's convenient we have script

micha03:08:39

ah i see what you did

micha03:08:48

appendChild we have

micha03:08:17

dude that's a nice lil ditty there

alandipert03:08:39

load-script! might be a handy thing to have

alandipert04:08:05

ty, i computed it just now

onetom04:08:20

they tried to load it as async as possible, that's why they have all that funkiness, imho

onetom04:08:32

@alandipert: and yes, inspectlet works really well. it's also a bit spooky at the same time because u can see users dumbness or hesitation or any small thing they do

alandipert04:08:55

seems crucial to have that visibility though

alandipert04:08:06

i would love to have it for our UI

onetom04:08:25

so the snippet u made i would just chuck in to the top level of my code?

onetom04:08:38

before (html ...) and that's it?

alandipert04:08:22

that's what i did

alandipert04:08:30

it complained about not having an ID, i suppose you need to set is somehow

onetom04:08:10

did u leave out the async attribute on purpose?

onetom04:08:32

yes, i will add the id

alandipert04:08:34

i'm not sure it does anything considering this is called after dom load

alandipert04:08:46

but my understanding of async is hazy

onetom04:08:43

hmm... might behave differently on different browsers, that's why they made it explicite

onetom04:08:02

i also see u did that loaded: null

onetom04:08:12

where did u get that from? the source if the library?

alandipert04:08:40

the top of inspectlet.js

onetom04:08:48

according to the snippet u r supposed to do a window.__insp = window.__insp || []; first

alandipert04:08:53

also not sure of significance

onetom04:08:58

similarly to how google analytics works

alandipert04:08:03

oh ok, that would be the thing to do in js*

onetom04:08:15

ok, i will try

onetom04:08:57

it feels like this inspectlet lib actually includes a jquery, no?

onetom04:08:07

maybe i should message them to just open source it

onetom04:08:16

so we can integrate more directly...

alandipert04:08:32

i saw what looked like code taht tests for it

onetom04:08:37

their core tech really is to collect scalably, retrieve and present nicely the recorded info...

micha04:08:10

haha you mean "computing"

onetom04:08:36

we are still getting a

Uncaught TypeError: Cannot read property 'scrollHeight' of null
error, so something is not happening right 😞

alandipert04:08:06

hm, that's coming from somewhere in inspectlet?

onetom04:08:04

yes, from inside. u dont get that error?

onetom04:08:25

we forgot to restart boot after we took out this inspectlet snippet from the cljs {:foreign-lib ...} config

onetom04:08:47

im also not sure about the purpose of

(str "http"
                         (when (= (-> js/document .-location .-protocol) "https:") "s")
                         "://cdn.inspectlet.com/inspectlet.js")
isn't this equivalent:
"//cdn.inspectlet.com/inspectlet.js"

alandipert04:08:31

i think the idea is, bring in the script with https if the page is https, so as not to pop browser warnings about "insecure content"

onetom04:08:43

and how saying //.... would be different?

onetom04:08:19

also @peterromfeld just said this should also work:

(str (-> js/document .-location .-protocol)
                         "//cdn.inspectlet.com/inspectlet.js")

alandipert04:08:45

that would work, but not for file:// prefix

alandipert04:08:09

maybe irreleavnt, i needed it as my test hoplon project was not running a server

onetom07:08:15

@micha: inspectlet gets fckd with alpha5 but works with alpha2

onetom08:08:25

we did a quick skim through of https://github.com/tailrecursion/hoplon/compare/6.0.0-alpha2...6.0.0-alpha5 but nothing jumped out at us obviously, since you changed the "rendering" logic fundamentally. BUT we also tried the "DOM Breakpoint" feature of Chrome to catch when the HMTL element is mutated and when inspectlet kicked in and we stepped thru the code, we saw that the merge-kids function was blowing away the head and the body elements, and thats why inspectlet couldn't hook it's scrollHeight attribute onto the document.body

onetom08:08:55

we also saw that merge-kids was removing the head first and that's when the content went back to being unstyled

onetom08:08:40

we could observe this when inspectlet.js kicked. the observation was made possibly by adding a little delay:

(defn inspect [field details]
  (.push js/__insp (clj->js [field details])))

(js* "window.__insp = window.__insp || [];")
(inspect "wid" (inspectlet-wid))

(with-init!
  (with-timeout
    2000
    (let [inspectlet-script
          (script :id "inspsync" :type "text/javascript" :src "/inspectlet.js")
          head-elem
          (aget (.getElementsByTagName js/document "head") 0)]
      (.appendChild head-elem inspectlet-script))))

(html ...)