mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-03 12:42:48 +03:00
first try at head-body separation
This commit is contained in:
parent
263730193c
commit
71adc8fb50
@ -382,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))
|
||||
}
|
||||
|
||||
'''
|
||||
::
|
||||
|
9
lib/urb-split.hoon
Normal file
9
lib/urb-split.hoon
Normal 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]
|
28
mar/urb.hoon
28
mar/urb.hoon
@ -2,13 +2,13 @@
|
||||
:::: /hoon/urb/mar
|
||||
::
|
||||
/? 314
|
||||
/= urb-wasp-data-js /: /%/wasp-data /js/
|
||||
!:
|
||||
|_ [dep=@uvH own=[[%html ~] [[%head ~] hed=marl] [[%body ~] tal=marl] ~]]
|
||||
::
|
||||
++ etag-js
|
||||
|_ [[dep=@uvH hed=marl] [dep-bod=@uvH bod=marl]]
|
||||
++ linked-deps-js
|
||||
'''
|
||||
urb.waspAll = function(sel){
|
||||
Array.prototype.map.call(document.querySelectorAll(sel), urb.waspElem)
|
||||
[].map.call(document.querySelectorAll(sel), urb.waspElem)
|
||||
}
|
||||
if(urb.wasp){urb.waspAll('script'); urb.waspAll('link')}
|
||||
'''
|
||||
@ -18,11 +18,23 @@
|
||||
++ html (crip (poxo hymn)) :: convert to %html
|
||||
++ hymn :: inject dependencies
|
||||
^- manx
|
||||
=: hed.own :_(hed.own ;meta(charset "utf-8", urb_injected "");)
|
||||
tal.own (welp tal.own ;script(urb_injected ""):"{(trip etag-js)}" ~)
|
||||
;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
|
||||
==
|
||||
?~ dep own
|
||||
own(hed :_(hed.own ;script@"/~/on/{<dep>}.js"(urb_injected "");))
|
||||
;body
|
||||
;* bod
|
||||
;script(urb_injected ""):"{(trip linked-deps-js)}"
|
||||
==
|
||||
==
|
||||
--
|
||||
++ grab
|
||||
|% :: convert from
|
||||
|
30
mar/urb/wasp-data.js
Normal file
30
mar/urb/wasp-data.js
Normal 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
14
ren/tree/body.hoon
Normal 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;
|
||||
==
|
||||
==
|
||||
==
|
@ -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;
|
||||
==
|
||||
==
|
||||
==
|
||||
==
|
13
ren/urb.hoon
13
ren/urb.hoon
@ -1,10 +1,11 @@
|
||||
::
|
||||
:::: /hoon/urb/ren
|
||||
::
|
||||
/# /%
|
||||
/^ [[%html ~] [[%head ~] hed=marl] [[%body ~] tal=marl] ~]
|
||||
/,
|
||||
/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/
|
||||
==
|
||||
-.-
|
||||
|
8
ren/urb/tree.hoon
Normal file
8
ren/urb/tree.hoon
Normal 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]
|
Loading…
Reference in New Issue
Block a user