aboutsummaryrefslogtreecommitdiffstats
path: root/root/meta/mmm.component/todoMVC
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-13 08:32:47 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-13 08:32:47 +0000
commit38c8a3ad5dd9b39fe03c1cdcd1f64ea9d0fc42d2 (patch)
treee550b0128b97147d9d02a829785cf2e7b0c7cec4 /root/meta/mmm.component/todoMVC
parentbegin documenting mmm.component (diff)
downloadmmm-38c8a3ad5dd9b39fe03c1cdcd1f64ea9d0fc42d2.tar.gz
mmm-38c8a3ad5dd9b39fe03c1cdcd1f64ea9d0fc42d2.zip
only pre-compile moonscript if no Lua variant available
Diffstat (limited to 'root/meta/mmm.component/todoMVC')
-rw-r--r--root/meta/mmm.component/todoMVC/text$lua -> mmm$component.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/root/meta/mmm.component/todoMVC/text$lua -> mmm$component.lua b/root/meta/mmm.component/todoMVC/text$lua -> mmm$component.lua
new file mode 100644
index 0000000..04dae47
--- /dev/null
+++ b/root/meta/mmm.component/todoMVC/text$lua -> mmm$component.lua
@@ -0,0 +1,45 @@
+local component = require 'mmm.component'
+local ReactiveVar, text, e = component.ReactiveVar, component.text, component.elements
+
+local parent = e.div()
+local function todoItem(desc, done)
+ -- convert into reactive data sources
+ local desc, done = ReactiveVar(desc), ReactiveVar(done)
+ local me = e.div{
+ style = {
+ margin = '8px',
+ padding = '8px',
+ background = '#eeeeee',
+ },
+ e.h3{ desc:map(text), style = 'margin: 0;' },
+ e.span(done:map(function (done)
+ if done then
+ return text 'done'
+ else
+ return text 'not done yet'
+ end
+ end)),
+ e.input{ type = 'checkbox', checked = done, onchange = function(_, e) done:set(e.target.checked) end },
+ e.a{ text 'delete', href = '#', onclick = function() parent:remove(me) end }
+ }
+ return me
+end
+
+parent:append(todoItem('write a Component System', true))
+parent:append(todoItem('eat Lasagna', true))
+parent:append(todoItem('do other things'))
+
+local desc = ReactiveVar 'start'
+local form = e.form{
+ action = '',
+ style = { margin = '2px' },
+ onsubmit = function(_, e)
+ e:preventDefault()
+ parent:append(todoItem(desc:get()))
+ desc:set ''
+ end,
+}
+form:append(e.input{ type = 'text', value = desc, onchange = function(_, e) desc:set(e.target.value) end })
+form:append(e.input{ type = 'submit', value = 'add' })
+
+return e.article(parent, form)