aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-01 07:10:38 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-01 07:10:38 +0000
commitd8daeb2a0b891bae03a7de2ae4ddf9e7b8b9f66b (patch)
treece843bc1325d095c825da354f14765bc3c72f0db
parentfix event handles in lib.dom (diff)
downloadmmm-d8daeb2a0b891bae03a7de2ae4ddf9e7b8b9f66b.tar.gz
mmm-d8daeb2a0b891bae03a7de2ae4ddf9e7b8b9f66b.zip
smooth navigation
-rw-r--r--lib/mmmfs/browser.moon56
-rw-r--r--lib/mmmfs/fileder.moon6
-rw-r--r--root/animations/init.moon6
-rw-r--r--root/articles/mmmfs/gallery.moon2
-rw-r--r--root/articles/realities.moon2
-rw-r--r--root/experiments/init.moon2
6 files changed, 38 insertions, 36 deletions
diff --git a/lib/mmmfs/browser.moon b/lib/mmmfs/browser.moon
index 5f70174..bd69fc0 100644
--- a/lib/mmmfs/browser.moon
+++ b/lib/mmmfs/browser.moon
@@ -24,25 +24,11 @@ class Browser
assert @root, 'root fileder is nil'
- -- @path\subscribe (path) -> window.location.hash = '/' .. table.concat path, '/'
- @active = @path\map (path) -> @root\walk path
-
--- fileder = @root
---
--- for name in *path
--- local next
--- for child in *fileder.children
--- if name == child\get 'name', 'alpha'
--- next = child
--- break
---
--- if not next
--- warn "couldn't find node '#{name}'"
--- return
---
--- fileder = next
---
--- fileder
+ @path\subscribe (path) ->
+ path ..= '/' unless path\match '/$'
+ window.history\pushState nil, '', path
+
+ @active = @path\map @root\walk
@prop = @active\map (fileder) ->
return unless fileder
@@ -77,15 +63,26 @@ class Browser
background: '#eeeeee',
},
span 'path: ', @path\map (path) -> with div style: { display: 'inline-block' }
- \append a 'root', href: '#', onclick: (_, e) ->
- e\preventDefault!
- @navigate {}
+ path_segment = (name, href) ->
+ a name, :href, onclick: (_, e) ->
+ e\preventDefault!
+ @navigate href
+
+ path = path\match '^/(.*)'
+ href = ''
+
+ \append path_segment 'root', '/'
+
+ while path
+ name, rest = path\match '^(%w+)/(.*)' -- or rest
+ if not name
+ name = path
+
+ path = rest
+ href = "#{href}/#{name}"
- for i,name in ipairs path
\append '/'
- \append a name, href: '#', onclick: (_, e) ->
- e\preventDefault!
- @navigate limit path, i
+ \append path_segment name, href
span 'view property: ', @active\map (fileder) ->
onchange = (_, e) ->
@@ -131,7 +128,7 @@ class Browser
if not prop
return disp_error "property not found!"
- ok, res = pcall ->
+ convert = ->
conversions = get_conversions 'mmm/dom', prop.type
value = assert (active\get prop), "value went missing?"
@@ -143,6 +140,11 @@ class Browser
value
+ ok, res = if MODE == 'CLIENT'
+ pcall convert
+ else
+ true, convert!
+
if ok
res or disp_error "[no conversion path to mmm/dom]"
else
diff --git a/lib/mmmfs/fileder.moon b/lib/mmmfs/fileder.moon
index a1f689e..c3e40f7 100644
--- a/lib/mmmfs/fileder.moon
+++ b/lib/mmmfs/fileder.moon
@@ -65,17 +65,17 @@ class Fileder
@props[k] = v
-- recursively walk to and return the fileder with @path == path
+ -- * path - the path to walk to
walk: (path) =>
-- early-out if we are outside of the path already
- return unless @path\match '^' .. path
+ return unless path\match '^' .. @path
-- gotcha
return @ if path == @path
- -- @TODO: obviously there is better ways
for child in *@children
result = child\walk path
- return if result
+ return result if result
-- recursively mount fileder and children at path
-- * path - the path to mount at (default: '/')
diff --git a/root/animations/init.moon b/root/animations/init.moon
index cb1f20a..ba8cb91 100644
--- a/root/animations/init.moon
+++ b/root/animations/init.moon
@@ -14,11 +14,9 @@ Fileder {
li {
a name, {
href: child.path,
- onclick: (_, e, ...) ->
- print 'ASD', e, ...
- window\alert 'YO WADDAFUQ'
+ onclick: (e) =>
e\preventDefault!
- BROWSER\navigate "animations | #{name}",
+ BROWSER\navigate child.path
},
': ', desc
}
diff --git a/root/articles/mmmfs/gallery.moon b/root/articles/mmmfs/gallery.moon
index 081865a..e132f42 100644
--- a/root/articles/mmmfs/gallery.moon
+++ b/root/articles/mmmfs/gallery.moon
@@ -14,7 +14,7 @@ with Fileder {
'moon -> mmm/dom': =>
link = (child) -> a {
href: '#',
- onclick: -> BROWSER\navigate { 'gallery', (child\get 'name', 'alpha'), nil },
+ onclick: -> BROWSER\navigate child.path
img src: child\gett 'preview', 'URL -> image/png'
}
diff --git a/root/articles/realities.moon b/root/articles/realities.moon
index f913842..5de8f6a 100644
--- a/root/articles/realities.moon
+++ b/root/articles/realities.moon
@@ -549,4 +549,6 @@ Fileder {
@phys!
@finish!
+
+ _content
}
diff --git a/root/experiments/init.moon b/root/experiments/init.moon
index 0beb78c..7b3a05d 100644
--- a/root/experiments/init.moon
+++ b/root/experiments/init.moon
@@ -16,7 +16,7 @@ Fileder {
href: child.path,
onclick: (e) =>
e\preventDefault!
- BROWSER\navigate "animations | #{name}",
+ BROWSER\navigate child.path
},
': ', desc
}