hoplon

The :hoplon: ClojureScript Web Framework - http://hoplon.io/
2017-12-22T02:03:42.000201Z

@alandipert it breaks native elements as soon as i drop hoplon.core into a ns

2017-12-22T02:04:04.000184Z

(ns app.main
 (:require
  [hoplon.core :as h]
  [javelin.core :as j]))

(let [el (.createElement js/document "div")
      body (.-body js/document)]
 (.appendChild body el)
 (.create js/BalloonEditor el))

2017-12-22T02:04:06.000100Z

this breaks

2017-12-22T02:04:15.000064Z

commenting out hoplon.core in the ns works

2017-12-22T02:05:09.000063Z

@flyboarder i think i'm going to try something like that, maybe wrapping all the prototype overrides in a native element check for safety

flyboarder 2017-12-22T02:05:38.000029Z

are they even needed?

flyboarder 2017-12-22T02:06:23.000160Z

I mean the attribute ones make sense

2017-12-22T02:06:27.000139Z

no idea, it seems to have some internal accounting with .-hoplonKids

2017-12-22T02:06:50.000154Z

if it's not needed then some low level stuff could be greatly simplified

2017-12-22T02:07:32.000235Z

but it also makes sense to me that there is some way to avoid what hoplon is doing if it conflicts with third party code

flyboarder 2017-12-22T02:07:40.000048Z

yep

2017-12-22T02:09:04.000240Z

also i wonder if we could implement IMeta for js elements and put "hoplon kids" in metadata to be more "clojurey"

flyboarder 2017-12-22T02:10:26.000027Z

yeah I was looking at that, why do we have hoplon kids? Is that just for child elements within a cell?

2017-12-22T02:12:06.000170Z

that could be it, would make sense

flyboarder 2017-12-22T02:12:58.000122Z

it seems like a case we should be able to negate, or remove if it breaks 3rd party stuff randomly

flyboarder 2017-12-22T02:13:23.000052Z

cells are for state, arguably children are not state

2017-12-22T02:13:29.000005Z

well i personally wouldn't expect low level native fns to support cells

2017-12-22T02:14:59.000201Z

mmm, maybe some cell-fu could be employed so the cells manage the DOM updating

2017-12-22T02:15:13.000020Z

rather than the DOM updating needing to be aware of cells

2017-12-22T02:15:28.000142Z

just thinking aloud ๐Ÿ™‚

flyboarder 2017-12-22T02:16:03.000223Z

a special โ€œparent awareโ€ cell perhaps

flyboarder 2017-12-22T02:16:30.000018Z

or NodeList cell

2017-12-22T02:17:43.000149Z

yeah, some kind of scoped contraption keeping an eye on what should go where

2017-12-22T02:18:30.000098Z

NodeList cell sounds like it would have to poll, which wouldn't scale ๐Ÿ˜•

2017-12-22T02:18:48.000031Z

but having the parent and a cell of children in the same scope makes sense to me at a high level

flyboarder 2017-12-22T02:18:57.000126Z

or maybe this can be replaced entirely with observer api?

2017-12-22T02:19:19.000090Z

oooh maybe

2017-12-22T02:19:33.000005Z

so that probably would bring some browser support into the picture

2017-12-22T02:19:48.000067Z

but also seems like potentially a good way to go with modern apis

flyboarder 2017-12-22T02:19:52.000120Z

i want to implement observer api for sure, just havnt had the time

2017-12-22T02:21:38.000143Z

this is the part of hoplon that seems the most like black magic to me, lol

2017-12-22T02:21:50.000111Z

messing with low level prototypes

2017-12-22T02:22:22.000017Z

also there are literally no comments/docs anywhere afaics

2017-12-22T02:34:12.000088Z

ok, well short term i will try out a basic detection and bypass strategy

2017-12-22T02:34:41.000115Z

i kind of need to do something because i have a subtly broken wysiwyg in my codebase now >.<

2017-12-22T02:38:49.000176Z

i feel a bit like my hair is on fire with this one ๐Ÿ˜›

2017-12-22T06:36:52.000116Z

ok, i can confirm the issue

2017-12-22T06:36:58.000033Z

(set-appendChild!  (.-prototype js/Element) #(.-hoplonKids %))
(set-removeChild!  (.-prototype js/Element) #(.-hoplonKids %))
(set-insertBefore! (.-prototype js/Element) #(.-hoplonKids %))
(set-replaceChild! (.-prototype js/Element) #(.-hoplonKids %))

2017-12-22T06:37:10.000054Z

commenting out this definitely fixes the bug in the wysiwyg

2017-12-22T06:37:36.000112Z

progress ๐Ÿ™‚

flyboarder 2017-12-22T06:38:09.000046Z

@thedavidmeister does it break the tests?

2017-12-22T06:39:13.000058Z

not sure yet

2017-12-22T06:39:39.000080Z

ideally i want to go "light touch" and keep everything as it is, except for non-hoplon elements

2017-12-22T06:39:54.000080Z

can chase up something more drastic later

2017-12-22T06:39:59.000111Z

also, what's the deal with set-setAttribute!?

2017-12-22T06:40:07.000196Z

it's only called in elem+

flyboarder 2017-12-22T06:41:08.000055Z

I have a feeling the hoplonKids thing is part of the experimental stuff

flyboarder 2017-12-22T06:41:14.000039Z

gonna look through commits

flyboarder 2017-12-22T06:44:03.000104Z

@thedavidmeister ah itโ€™s for *-tpl macros

2017-12-22T06:45:02.000019Z

well that's the other potential approach

2017-12-22T06:45:09.000017Z

rather than trying to do a detection

2017-12-22T06:45:28.000061Z

maybe this could be shifted into mkelem

2017-12-22T06:46:27.000084Z

or some metadata added to the created element in mkelem that would make detection robust

2017-12-22T06:46:47.000070Z

atm native? looks like

2017-12-22T06:46:49.000200Z

(defn- native?
  "Returns true if elem is a native element. Native elements' children
  are not managed by Hoplon."
  [elem]
  (and (instance? js/Element elem)
       (-&gt; elem .-hoplonKids nil?)))

2017-12-22T06:47:07.000006Z

doesn't feel super robust to me, is hoplonKids really safe to rely on? i dunno

flyboarder 2017-12-22T06:49:16.000124Z

currently itโ€™s safe since thats how the tplโ€™s work, but if they change then maybe not

2017-12-22T06:50:35.000206Z

yeah, safe in context of the fact that native? is used relatively little

2017-12-22T06:50:53.000119Z

but can it reliably detect the difference between a hoplon and non-hoplon element in a more general setting?

2017-12-22T06:52:45.000067Z

so many questions, lol

flyboarder 2017-12-22T06:52:51.000011Z

yep should be using satisfies?

flyboarder 2017-12-22T06:54:29.000045Z

ie (satisfies? ICustomElement el) < 7.1-SNAPSHOT < (satisfies? IHoplonElement el)

2017-12-22T06:54:56.000035Z

mmm, there's -insert-before! in the protocol

2017-12-22T06:55:28.000010Z

but not actually used

2017-12-22T06:56:00.000175Z

looks like it's just intended for external use? but then everything in hoplon internals uses the overridden protocol

2017-12-22T06:57:48.000162Z

IHoplonElement is implemented for all js/Element atm, not just those created by hoplon

2017-12-22T06:58:15.000094Z

i actually like the js/Element extension as it means we can use IFn etc.

2017-12-22T06:58:44.000051Z

but that's an extension of native functionality, not an override...

flyboarder 2017-12-22T07:00:17.000117Z

yeah we are mixing extending and overriding

flyboarder 2017-12-22T07:01:08.000024Z

seems we have to support cells as children while the tpl macros return a cell

2017-12-22T07:01:25.000042Z

mhmm

2017-12-22T07:02:18.000129Z

so, let's say i want to make insertBefore have a safe fallback for native elements

2017-12-22T07:02:22.000121Z

well, there are 3 elements there

2017-12-22T07:02:31.000042Z

the parent, the reference element and the thing being inserted

2017-12-22T07:02:58.000101Z

do they all need to be non-hoplon, or just the parent, or something else to trigger the native functionality?

2017-12-22T07:03:43.000090Z

probably need to check that all three are not cells, right?

flyboarder 2017-12-22T07:09:09.000043Z

no I think just the children is fine still

2017-12-22T07:14:46.000129Z

kk

flyboarder 2017-12-22T07:18:52.000017Z

looking through this, Iโ€™ll need to dig deeper and see how much of it is really needed, perhaps @micha can shed some light

flyboarder 2017-12-22T07:19:31.000068Z

@thedavidmeister for now I think the native? check should be fine as a workaround

2017-12-22T07:21:10.000026Z

it does feel like a refactor might be possible...

flyboarder 2017-12-22T07:21:36.000095Z

yeah I think itโ€™s warranted since this also causes your dom-cache bug

flyboarder 2017-12-22T07:22:04.000233Z

and there is a bunch of other things I am seeing which arenโ€™t needed anymore

flyboarder 2017-12-22T07:23:01.000020Z

Iโ€™m hitting the pillow for tonight but ill poke a few things tomorrow

2017-12-22T07:23:23.000162Z

np, i'll keep tinkering here for a bit ๐Ÿ™‚

2017-12-22T07:24:58.000173Z

also we should try to make hoplon parinfer compatible at some point >.<

2017-12-22T07:25:31.000139Z

i'm manually lining up parens like a schmuck over here

flyboarder 2017-12-22T07:25:41.000142Z

we still need to update tests and split for jquery/goog

2017-12-22T07:26:33.000033Z

mmm, well i saw clojure 1.9 landed

flyboarder 2017-12-22T07:26:41.000126Z

yep already got that included ๐Ÿ˜‰

2017-12-22T07:26:45.000042Z

so we should do some triage and plan a 7.1

2017-12-22T07:26:53.000060Z

we can always push some of this stuff to a 7.2 release

2017-12-22T07:27:01.000075Z

there's a ton of good work in 7.1 already

flyboarder 2017-12-22T07:27:35.000032Z

true! maybe we save ourselves with a 7.1 for all the existing work and move anything else to 7.2

flyboarder 2017-12-22T07:27:54.000122Z

7.1 proposal PR completed all the checkboxes I think

2017-12-22T07:27:55.000021Z

don't want to fall into the neverending "one more thing" trap

flyboarder 2017-12-22T07:28:31.000268Z

https://github.com/hoplon/hoplon/issues/184

2017-12-22T07:28:36.000019Z

it actually makes things worse IMO because you end up with a really spiky upgrade path when too much change at once

2017-12-22T07:29:17.000081Z

geez IE8

flyboarder 2017-12-22T07:29:53.000026Z

yeah, personally I would also like to move all the element constructors to their own ns (hoplon.html5) like the hoplon.svg keep core to the business logic

2017-12-22T07:29:55.000027Z

yes we've gone above and beyond that checklist

2017-12-22T07:30:23.000248Z

well changing ns should definitely be its own version

2017-12-22T07:30:43.000211Z

you know ppl are going to have to re-organise downstream when that happens

flyboarder 2017-12-22T07:31:13.000244Z

yeah maybe save that one for Hoplon 8 hahahaha

2017-12-22T07:31:35.000016Z

you could go real deep there...

2017-12-22T07:31:59.000193Z

like imo most of the common core functionality can be handled easily by native JS, no jquery or goog needed

2017-12-22T07:32:02.000068Z

except events

2017-12-22T07:32:07.000001Z

jquery normalises those well

2017-12-22T07:32:33.000074Z

you could end up with hoplon.jquery.events ๐Ÿ˜›

flyboarder 2017-12-22T07:33:03.000004Z

oh the rabbit hole

2017-12-22T07:33:11.000154Z

yeah that's a bike shed for another day i think

flyboarder 2017-12-22T07:33:27.000108Z

anyway night ๐ŸŒ™

2017-12-22T07:33:30.000134Z

cya

2017-12-22T08:15:12.000147Z

ok, so looks like native? doesn't work the way that i expected

2017-12-22T08:17:02.000176Z

returning false for elements created by wysiwyg and/or contenteditable

2017-12-22T08:17:38.000162Z

tbh i don't know whether these elements are created by the browser or ckeditor or both ๐Ÿ˜›

2017-12-22T08:27:16.000139Z

hmmm, might be because of text #object[Text [object Text]]

2017-12-22T08:49:18.000081Z

ok i think i fixed it!

2017-12-22T08:49:24.000221Z

hopefully i didn't break anything else in the process

2017-12-22T08:49:47.000097Z

need to check (instance? js/Node node) rather than (instance? js/Element elem)

2017-12-22T08:50:30.000056Z

these functions are actually on the Node prototype too

2017-12-22T08:52:51.000173Z

except setAttribute, that is only available for elements, not all nodes

2017-12-22T14:02:21.000251Z

@flyboarder @alandipert https://github.com/hoplon/hoplon/pull/205/files#diff-eb8092184c02e48bc9df45c8bb1a8dafR160 tests (and fixes) for hoplon checking whether an element is native? ๐Ÿ™‚

flyboarder 2017-12-22T19:40:23.000025Z

@thedavidmeister so im glad you figured it out, however I have mixed feelings about why itโ€™s happening, we are essentially going against the protocol by overriding the prototype. We should be using specify on the element constructor to implement those changes instead of touching the prototype of the elements

flyboarder 2017-12-22T19:44:12.000159Z

I still think a refactor would be most appropriate.

2017-12-22T21:22:13.000212Z

flyboarder thedavidmeister unfortunately i can't remember anything about this or why it is the way it is

flyboarder 2017-12-22T22:11:07.000028Z

@alandipert how do you feel about PR #199??

2017-12-22T22:18:57.000074Z

i scrolled through the diff and it looks very nice :-)

2017-12-22T22:19:06.000120Z

is there anything in particular you could use more detailed feedback on?

flyboarder 2017-12-22T23:10:25.000158Z

@alandipert not specifically, just looking for approval other than @thedavidmeister and myself ๐Ÿ˜›

flyboarder 2017-12-22T23:13:19.000055Z

unless you have a project you might be able to try the 7.1-SNAPSHOT on

2017-12-22T23:43:34.000044Z

@flyboarder yes i agree that a refactor would be better, but the prototype is already overwritten

2017-12-22T23:43:54.000110Z

i'm just going for a quick fix, that i can write some tests against

2017-12-22T23:44:14.000156Z

and then we can followup with a refactor - i'm thinking that could be one of the first things in 7.2

flyboarder 2017-12-22T23:45:30.000136Z

yep agreed!

2017-12-22T23:45:51.000036Z

i'm going to spend some time today just writing tests for all this

flyboarder 2017-12-22T23:46:41.000067Z

ok, ill wait to cut 7.1 until then, should we merge your fixes for this as 7.0.4?

flyboarder 2017-12-22T23:46:53.000074Z

or just roll it into 7.1?

2017-12-22T23:46:59.000089Z

i started the branch off 7.1

2017-12-22T23:47:12.000015Z

so probably roll it in

flyboarder 2017-12-22T23:47:23.000029Z

ok sounds good, ill wait till you have the tests worked out

2017-12-22T23:48:18.000139Z

ok, unless any there are surprises i should be able to get that sorted today