aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-10-30 03:17:58 +0000
committers-ol <s-ol@users.noreply.github.com>2018-10-30 03:17:58 +0000
commit72a5f7a96105b706bc22a4539e91efa325c83b89 (patch)
treee0155024e6796e74928b210490501c6456204331 /lib
parentway better client requires (diff)
downloadmmm-72a5f7a96105b706bc22a4539e91efa325c83b89.tar.gz
mmm-72a5f7a96105b706bc22a4539e91efa325c83b89.zip
fix switching
Diffstat (limited to 'lib')
-rw-r--r--lib/mmmfs/browser.moon14
-rw-r--r--lib/mmmfs/fileder.moon98
-rw-r--r--lib/mmmfs/init.moon93
3 files changed, 110 insertions, 95 deletions
diff --git a/lib/mmmfs/browser.moon b/lib/mmmfs/browser.moon
index 427d952..d342be8 100644
--- a/lib/mmmfs/browser.moon
+++ b/lib/mmmfs/browser.moon
@@ -1,3 +1,6 @@
+require = relative ..., 1
+import Key from require '.fileder'
+import get_conversions from require '.conversion'
import ReactiveVar, text, elements from require 'lib.component'
import div, span, a, select, option from elements
@@ -78,9 +81,14 @@ class Browser
active = @active\get!
ok, res = pcall ->
- -- val, key = active\get prop.name, prop.type
- -- CONVERT 'mmm/dom', val, key
- active\get prop.name, 'mmm/dom'
+ conversions = assert (get_conversions 'mmm/dom', prop.type), "no conversion path"
+ value = assert (active\get prop), "value went missing?"
+
+ for i=#conversions,1,-1
+ { :inp, :out, :transform } = conversions[i]
+ value = transform value, active
+
+ value
if ok and res
res
diff --git a/lib/mmmfs/fileder.moon b/lib/mmmfs/fileder.moon
new file mode 100644
index 0000000..75659d4
--- /dev/null
+++ b/lib/mmmfs/fileder.moon
@@ -0,0 +1,98 @@
+require = relative ..., 1
+import get_conversions from require '.conversion'
+
+-- Key of a Fileder Property
+-- contains:
+-- * @name - key name or '' for main content
+-- * @type - type string (type -> type -> type)
+class Key
+ -- instantiate from table w/ keys described above
+ -- or string like '@name: @type' (name optional)
+ new: (opts, second) =>
+ if 'string' == type second
+ @name, @type = (opts or ''), second
+ elseif 'string' == type opts
+ @name, @type = opts\match '(%w+): *(.+)'
+ if not @name
+ @name = ''
+ @type = opts
+ elseif 'table' == type opts
+ @name = opts.name
+ @type = opts.type
+ else
+ error "wrong argument type: #{type opts}, #{type second}"
+
+ -- format as a string (see constructor)
+ tostring: =>
+ if @name == ''
+ @type
+ else
+ "#{@name}: #{@type}"
+
+-- Fileder itself
+-- contains:
+-- * @props - Property Map (Key to Value)
+-- * @children - Children Array
+class Fileder
+ -- instantiate from props and children tables
+ -- or mix in one table (numeric keys are children, remainder props)
+ -- prop-keys are passed to Key constructor
+ new: (props, @children) =>
+ if not @children
+ @children = for i, child in ipairs props
+ props[i] = nil
+ child
+
+ @props = { (Key k), v for k, v in pairs props }
+
+ -- find property key according to criteria, nil if no value or conversion path
+ -- * name - property name (optional: defaults to main content)
+ -- * type - wanted result type
+ find: (...) =>
+ want = Key ...
+
+ -- filter props by name
+ matching = [ key for key in pairs @props when key.name == want.name ]
+ return unless #matching > 0
+
+ -- get shortest conversion path
+ shortest_path, start = get_conversions want.type, [ key.type for key in *matching ]
+
+ if start
+ for key in *matching
+ if key.type == start
+ return key, shortest_path
+
+ error "couldn't find key after resolution?"
+
+ -- get property according to criteria, nil if no value or conversion path
+ -- * name - property name (optional: defaults to main content)
+ -- * type - wanted result type
+ get: (...) =>
+ want = Key ...
+
+ -- find matching key and shortest conversion path
+ key, conversions = @find want
+
+ if key
+ value = @props[key]
+
+ -- apply conversions (in reverse order)
+ for i=#conversions,1,-1
+ { :inp, :out, :transform } = conversions[i]
+ value = transform value, @
+
+ value, key
+
+ -- like @get, throw if no value or conversion path
+ gett: (...) =>
+ want = Key ...
+
+ value, key = @get want
+ assert value, "node doesn't have value for #{want\tostring!}"
+ value, key
+
+{
+ :Key
+ :Fileder
+}
diff --git a/lib/mmmfs/init.moon b/lib/mmmfs/init.moon
index 2393c75..bb26505 100644
--- a/lib/mmmfs/init.moon
+++ b/lib/mmmfs/init.moon
@@ -1,96 +1,5 @@
require = relative ...
-import get_conversions from require '.conversion'
-
--- Key of a Fileder Property
--- contains:
--- * @name - key name or '' for main content
--- * @type - type string (type -> type -> type)
-class Key
- -- instantiate from table w/ keys described above
- -- or string like '@name: @type' (name optional)
- new: (opts, second) =>
- if 'string' == type second
- @name, @type = (opts or ''), second
- elseif 'string' == type opts
- @name, @type = opts\match '(%w+): *(.+)'
- if not @name
- @name = ''
- @type = opts
- elseif 'table' == type opts
- @name = opts.name
- @type = opts.type
- else
- error "wrong argument type: #{type opts}, #{type second}"
-
- -- format as a string (see constructor)
- tostring: =>
- if @name == ''
- @type
- else
- "#{@name}: #{@type}"
-
--- Fileder itself
--- contains:
--- * @props - Property Map (Key to Value)
--- * @children - Children Array
-class Fileder
- -- instantiate from props and children tables
- -- or mix in one table (numeric keys are children, remainder props)
- -- prop-keys are passed to Key constructor
- new: (props, @children) =>
- if not @children
- @children = for i, child in ipairs props
- props[i] = nil
- child
-
- @props = { (Key k), v for k, v in pairs props }
-
- -- find property key according to criteria, nil if no value or conversion path
- -- * name - property name (optional: defaults to main content)
- -- * type - wanted result type
- find: (...) =>
- want = Key ...
-
- -- filter props by name
- matching = [ key for key in pairs @props when key.name == want.name ]
- return unless #matching > 0
-
- -- get shortest conversion path
- shortest_path, start = get_conversions want.type, [ key.type for key in *matching ]
-
- if start
- for key in *matching
- if key.type == start
- return key, shortest_path
-
- error "couldn't find key after resolution?"
-
- -- get property according to criteria, nil if no value or conversion path
- -- * name - property name (optional: defaults to main content)
- -- * type - wanted result type
- get: (...) =>
- want = Key ...
-
- -- find matching key and shortest conversion path
- key, conversions = @find want
-
- if key
- value = @props[key]
-
- -- apply conversions (in reverse order)
- for i=#conversions,1,-1
- { :inp, :out, :transform } = conversions[i]
- value = transform value, @
-
- value, key
-
- -- like @get, throw if no value or conversion path
- gett: (...) =>
- want = Key ...
-
- value, key = @get want
- assert value, "node doesn't have value for #{want\tostring!}"
- value, key
+import Key, Fileder from require '.fileder'
{
:Key