aboutsummaryrefslogtreecommitdiffstats
path: root/lib
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 /lib
parentfix event handles in lib.dom (diff)
downloadmmm-d8daeb2a0b891bae03a7de2ae4ddf9e7b8b9f66b.tar.gz
mmm-d8daeb2a0b891bae03a7de2ae4ddf9e7b8b9f66b.zip
smooth navigation
Diffstat (limited to 'lib')
-rw-r--r--lib/mmmfs/browser.moon56
-rw-r--r--lib/mmmfs/fileder.moon6
2 files changed, 32 insertions, 30 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: '/')