Merge branch 'data-dep' into tree-comments

handle chrome/data separation in an official manner
This commit is contained in:
Anton Dyudin 2016-02-09 19:43:19 -08:00
commit bd143385c5
10 changed files with 136 additions and 93 deletions

View File

@ -197,15 +197,6 @@
=+ cuh=(turn `(list ,@t)`cug |=(a=@t set-cookie/a))
hit(q (weld cuh q.hit))
::
++ inject :: inject dependency
|= [dep=@uvH max=[[%html ~] [[%head ~] hed=marl] [[%body ~] tal=marl] ~]]
^- manx
=: hed.max :_(hed.max ;meta(charset "utf-8", urb_injected "");)
tal.max (welp tal.max ;script(urb_injected ""):"{(trip etag:js)}" ~)
==
?~ dep max
max(hed :_(hed.max ;script@"/~/on/{<dep>}.js"(urb_injected "");))
::
++ add-json :: inject window.urb
|= [urb=json jaz=cord] ^- cord
=- (cat 3 (crip -) jaz)
@ -228,13 +219,14 @@
[sas ~[content-type/(moon mit)] [~ (taco rez)]]
::
++ render-tang :: tanks to manx
|= tan=tang
|= [dep=@uvH tan=tang]
;html
;head
;link(rel "stylesheet", href "/lib/base.css");
;title: server error
==
;body:div#c.err:pre:code:"{(wush 80 tan)}"
;script@"/~/on/{<dep>}.js";
==
::
++ favi :: XX favicon
@ -390,23 +382,6 @@
urb.wreq.abort() // trigger keep
}
}
urb.waspElem = function(ele){
url = ele.src || ele.href
if(!url || (new URL(url)).host != document.location.host)
return;
urb.waspUrl(url)
}
urb.waspUrl = function(url){
var xhr = new XMLHttpRequest()
xhr.open("HEAD", url)
xhr.send()
xhr.onload = urb.waspLoadedXHR
}
urb.waspLoadedXHR = function(){urb.wasp(urb.getXHRWasp(this))}
urb.getXHRWasp = function(xhr){
var dep = xhr.getResponseHeader("etag")
if(dep) return JSON.parse(dep.substr(2))
}
'''
::
@ -461,14 +436,6 @@
function(){document.getElementById("c").innerHTML = "" }
)}
'''
++ etag
'''
if(!window.urb) window.urb = {}
urb.waspAll = function(sel){
Array.prototype.map.call(document.querySelectorAll(sel), urb.waspElem)
}
if(urb.wasp){urb.waspAll('script'); urb.waspAll('link')}
'''
--
++ xml
|%
@ -847,16 +814,7 @@
?. ?=(%mime p.cay)
=+ bek=-:(need (tome p.tee))
=+ bik=?+(r.bek bek [%ud %0] bek(r da/now))
=- (execute tee bik [%flag [p.sih `~] -])
=- `silk`[%cast %mime `[p.cay -]]
?. ?=([%ud 0] r.bek) q.cay
?+ p.cay q.cay :: inject dependency long-poll
%urb =< (slam !>(.) q.cay)
|= urb=manx
~| [%malformed-urb urb]
?> ?=([[%html ~] [[%head ~] *] [[%body ~] *] ~] urb)
(inject p.sih urb)
==
(execute tee bik [%flag [p.sih `~] %cast %mime q.sih])
~| q.q.cay
=+ ((hard ,[mit=mite rez=octs]) q.q.cay)
=+ dep=(crip "W/{(pojo %s (scot %uv p.sih))}")
@ -920,7 +878,7 @@
|= [sas=@ud dep=@uvH mez=tang]
^+ +>
:: (back ha/~ dep %tang !>(mez)) ::tang->urb chain may be source of failure
(give-html sas ~ (inject dep (render-tang mez)))
(give-html sas ~ (render-tang dep mez))
::
++ give-html
|= [sas=@ud cug=(list ,@t) max=manx]

View File

@ -48,6 +48,7 @@
++ cafe :: live cache
$: p=(set calx) :: used
q=(map ,* calx) :: cache
r=(map ,@uvH deps) :: dependss
== ::
:: ::
++ calm :: cache metadata
@ -101,11 +102,6 @@
^- cafe ::
a(q (~(put by q.a) [-.b q.b] b)) ::
:: ::
++ chub :: cache merge
|= [a=cafe b=cafe] ::
^- cafe ::
[(~(uni in p.a) p.b) (~(uni by q.a) q.b)] ::
:: ::
++ faun (flux |=(a=vase [%& %noun a])) :: vase to gage
++ feel (flux |=(a=cage q.a)) :: cage to vase
++ furl :: unwrap gage to cage
@ -316,6 +312,12 @@
[%warp [our p.bem] q.bem [~ %sing ren r.bem (flop s.bem)]]
==
::
++ clad :: hash dependencies
|* hoc=(bolt) ^+ [*@uvH hoc]
?: ?=(%1 -.q.hoc) [*@uvH hoc]
=^ dep r.p.hoc (daze [p.q r.p]:hoc)
[dep hoc]
::
++ clef :: cache a result
|* sem=*
|* [hoc=(bolt) fun=(burg)]
@ -485,7 +487,7 @@
++ dash :: process cache
|= cof=cafe
^+ +>
%_(+> jav.bay q.cof)
%_(+> jav.bay q.cof, deh.bay r.cof)
::
++ diff :: diff
|= [cof=cafe kas=silk kos=silk]
@ -532,29 +534,28 @@
==
::
++ daze :: remember depends
|= dep=(set beam)
^+ [*@uvH deh.bay]
|= [dep=(set beam) deh=(map ,@uvH deps)]
^+ [*@uvH deh]
=. dep
=< (sa (skip (~(tap in dep)) .))
|= dap=beam ^- ?
?~ s.dap |
=>(.(s.dap t.s.dap) |((~(has in dep) dap) $))
?~ dep [0v0 deh.bay]
?~ dep [0v0 deh]
=+ hap=(sham dep)
?: (~(has by deh.bay) hap)
[hap deh.bay]
[hap (~(put by deh.bay) hap [%init dep])]
?: (~(has by deh) hap)
[hap deh]
[hap (~(put by deh) hap [%init dep])]
::
++ exec :: execute app
^+ ..zo
?: !=(~ q.kig) ..zo
=+ bot=(make [~ jav.bay] kas)
=+ bot=(make [~ jav.bay deh.bay] kas)
=^ dep bot (clad bot)
=. ..exec (dash p.bot)
?- -.q.bot
%0 =^ dep deh.bay (daze p.q.bot)
amok:(expo [%made dep q.q.bot])
%2 =^ dep deh.bay (daze p.q.bot)
amok:(expo [%made dep %| q.q.bot])
%0 amok:(expo [%made dep q.q.bot])
%2 amok:(expo [%made dep %| q.q.bot])
%1 =+ zuk=(~(tap by p.q.bot) ~)
=< abet
|- ^+ ..exec
@ -678,6 +679,7 @@
(stag %ape ;~(pfix sig ape:read))
(stag %arg ;~(pfix buc ape:read))
(stag %alt ;~(pfix bar alt:read))
(stag %dep ;~(pfix hax day:read))
(stag %dub ;~(pfix tis dub:read))
(stag %fan ;~(pfix dot fan:read))
(stag %for ;~(pfix com for:read))
@ -1431,10 +1433,19 @@
|= cof=cafe ^- (bolt cage)
?~ p.hon (flaw cof leaf/"ford: out of options" ~)
(coop ^$(cof cof, hon i.p.hon) ..$(p.hon t.p.hon))
::
%dep
=+ [dep bot]=(clad $(hon p.hon)) :: XX review
%+ cope bot
%- flux
|= [mark vax=vase]
[%noun (slop [atom/'uvH' dep] vax)]
::
%dub
%+ cope $(hon q.hon)
(flux |=([mar=mark vax=vase] [mar [%face p.hon p.vax] q.vax]))
%- flux
|= [mar=mark vax=vase]
[mar [%face p.hon p.vax] q.vax]
::
%fan
%- cope :_ (flux |=(a=vase noun/a))
@ -1675,7 +1686,7 @@
?> (~(has by q.kig) tik)
=+ `[ren=care bem=beam]`(~(got by q.kig) tik)
?~ rot
=^ dep deh.bay (daze ~) :: dependencies?
=^ dep deh.bay (daze ~ deh.bay) :: dependencies?
amok:(expo [%made dep %| (smyt ren (tope bem)) ~])
=+ (cat 3 'c' ren)
exec(q.kig (~(del by q.kig) tik), keg (~(put by keg) [- bem] r.u.rot))

View File

@ -2493,6 +2493,7 @@
$% [%ape p=twig] :: /~ twig by hand
[%arg p=twig] :: /$ argument
[%alt p=(list horn)] :: /| options
[%dep p=horn] :: /# insert dephash
[%dub p=term q=horn] :: /= apply face
[%fan p=(list horn)] :: /. list
[%for p=(list (pair path:spur horn))] :: /, switch by path

9
lib/urb-split.hoon Normal file
View File

@ -0,0 +1,9 @@
::
:::: /hoon/urb-split/lib
::
|= [dep=@uvH urb=manx] ^- [hed=[@uvh marl] bod=[@uvH marl]]
~| [%malformed-urb urb] :: XX types
?> ?=([[%html ~] [[%head ~] *] [[%body ~] *] ~] urb)
=+ `[[%html ~] [[%head ~] hed=marl] [[%body ~] bod=marl] ~]`urb
:- [dep hed] :: Assume all dependencies are hard
[0v0 bod]

View File

@ -2,19 +2,42 @@
:::: /hoon/urb/mar
::
/? 314
/= urb-wasp-data-js /: /%/wasp-data /js/
!:
|_ own=manx
::
|_ [[dep=@uvH hed=marl] [dep-bod=@uvH bod=marl]]
++ linked-deps-js
'''
urb.waspAll = function(sel){
[].map.call(document.querySelectorAll(sel), urb.waspElem)
}
if(urb.wasp){urb.waspAll('script'); urb.waspAll('link')}
'''
++ grow :: convert to
|%
++ html (crip (poxo own)) :: convert to %html
++ mime [/text/html (taco html)] :: convert to %mime
++ html (crip (poxo hymn)) :: convert to %html
++ hymn :: inject dependencies
^- manx
;html
;head
;meta(charset "utf-8", urb_injected "");
;* ?~ dep ~
:~ ;script@"/~/on/{<dep>}.js"(urb_injected "");
;script(urb_injected "")
;- (trip urb-wasp-data-js)
;- "urb.waspData({(pojo %s (scot %uv dep-bod))})"
==
==
;* hed
==
;body
;* bod
;script(urb_injected ""):"{(trip linked-deps-js)}"
==
==
--
++ grab
|% :: convert from
++ noun manx :: clam from %noun
:: conversion from hymn is handled specially by %eyre,
:: which injects dependency information
:: ++ hymn !! :: inject into %hymn
++ noun ,[@uvH manx] :: clam from %noun
--
--

30
mar/urb/wasp-data.js Normal file
View File

@ -0,0 +1,30 @@
urb.waspElem = function(ele){
url = ele.src || ele.href
if(!url || (new URL(url)).host != document.location.host)
return;
urb.waspUrl(url)
}
urb.waspUrl = function(url){
var xhr = new XMLHttpRequest()
xhr.open("HEAD", url)
xhr.send()
xhr.onload = urb.waspLoadedXHR
}
urb.waspLoadedXHR = function(){urb.wasp(urb.getXHRWasp(this))}
urb.getXHRWasp = function(xhr){
var dep = xhr.getResponseHeader("etag")
if(dep) return JSON.parse(dep.substr(2))
}
urb.datadeps = {}
urb.waspData = function(dep){
urb.datadeps[dep] = true
urb.wasp(dep)
}
urb.ondataupdate = urb.onupdate // overridable
var _onupdate = urb.onupdate
urb.onupdate = function(dep){
if(urb.datadeps[dep]) urb.ondataupdate(dep)
else _onupdate(dep)
}

14
ren/tree/body.hoon Normal file
View File

@ -0,0 +1,14 @@
::
:::: /hoon/body/tree/ren
::
/? 314
/= dat /% /tree-json/ :: default include
^- marl
;= ;script(type "text/javascript"): window.tree = {(pojo (joba %data dat))}
;div.container
;div.row#main
;div#head;
;div#body;
==
==
==

View File

@ -1,10 +1,8 @@
::
:::: /hoon/hymn/tree/ren
:::: /hoon/head/tree/ren
::
::
/? 314
/- tree-include
/= dat /% /tree-json/ :: default include
/= tub /$ |=([bem=beam *] (flop s.bem))
/= aut
/$ %+ cork fuel :: after parsing params,
@ -15,9 +13,8 @@
!:
::::
::
;html
;head
;title: Tree
^- marl
;= ;title: Tree
;meta(name "viewport", content "width=device-width, initial-scale=1");
;link(type "text/css", rel "stylesheet", href "//cdnjs.cloudflare.com/ajax/libs/codemirror/4.3.0/codemirror.min.css");
;link(type "text/css", rel "stylesheet", href "/lib/css/fonts.css");
@ -39,14 +36,4 @@
"codemirror/4.3.0/mode/markdown/markdown.min.js");
;script(type "text/javascript", src "{?.(aut "" "/~~")}".
"/~/at/lib/js/urb.js");
==
;body
;script(type "text/javascript"): window.tree = {(pojo (joba %data dat))}
;div.container
;div.row#main
;div#head;
;div#body;
==
==
==
==

View File

@ -1,9 +1,11 @@
::
:::: /hoon/urb/ren
::
/% /,
/talk/log /talklog-hymn/
/web/app /|(/!hymn/ /tree-hymn/)
/ /tree-hymn/
/+ urb-split :: for single-page apps
/% /^ [hed=[@uvH marl] bod=[@uvH marl]]
/, /web/app
/|(/;urb-split;/#/!hymn/ /urb-tree/)
/
/urb-tree/
==
`manx`-.-
-.-

8
ren/urb/tree.hoon Normal file
View File

@ -0,0 +1,8 @@
:: Combine /tree-head/ and /tree-body/
::
:::: /hoon/urb/ren
::
/= hed /# /% /: /===/ren /tree-head/ :: XX static
/= bod /# /% /tree-body/
^- [hed=[@uvH marl] bod=[@uvH marl]]
[hed bod]