aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-10-27 12:28:38 +0000
committers-ol <s-ol@users.noreply.github.com>2018-10-27 12:28:38 +0000
commit416af672c415341b35aec9c99428324b2265419d (patch)
treec8b9ccdff893b5d18ed43ab58eb8367d5d08e8fd
parentmore friendly description (diff)
downloadmmm-416af672c415341b35aec9c99428324b2265419d.tar.gz
mmm-416af672c415341b35aec9c99428324b2265419d.zip
infinite table for lib.component
-rw-r--r--app/realities.moon3
-rw-r--r--app/tags/init.moon3
-rw-r--r--app/test_component.moon6
-rw-r--r--app/todo.moon3
-rw-r--r--lib/component.client.moon44
-rw-r--r--lib/component.server.moon27
6 files changed, 56 insertions, 30 deletions
diff --git a/app/realities.moon b/app/realities.moon
index 773f62f..86da107 100644
--- a/app/realities.moon
+++ b/app/realities.moon
@@ -1,4 +1,5 @@
-import append, h1, h2, p, a, i, div, ol, li, br, hr, span, button, section, article from require 'lib.component'
+import append, elements from require 'lib.component'
+import h1, h2, p, a, i, div, ol, li, br, hr, span, button, section, article from elements
if MODE == 'CLIENT'
require 'svg.js'
diff --git a/app/tags/init.moon b/app/tags/init.moon
index 75469ea..e3198f8 100644
--- a/app/tags/init.moon
+++ b/app/tags/init.moon
@@ -1,7 +1,8 @@
on_client ((...) ->
require = relative ...
import add_tag, rmv_tag, Node, Hierarchy, Toggle, NamespacedToggle from require '.tags'
- import ReactiveVar, append, tohtml, text, div, form, span, h3, a, input, textarea, button from require 'lib.component'
+ import ReactiveVar, append, tohtml, text, elements from require 'lib.component'
+ import div, form, span, h3, a, input, textarea, button from elements
clone = (set) ->
assert set and 'table' == (type set), 'not a set'
diff --git a/app/test_component.moon b/app/test_component.moon
index dba511b..9e3a0ed 100644
--- a/app/test_component.moon
+++ b/app/test_component.moon
@@ -50,6 +50,12 @@ on_client ->
node = text 'a', 'test', 'string'
assert node.data == 'a test string', "expected text to join arguments with spaces"
+ run_test "exports elements table", ->
+ import elements from require 'lib.component'
+
+ assert (type elements.div!) == 'table', "expected to build element with elements.div!"
+ assert (type elements.madeup!) == 'table', "expected to build element with elements.madeup!"
+
run_test = test_group 'ReactiveVar'
run_test "stores a value", ->
diff --git a/app/todo.moon b/app/todo.moon
index 5a1aa47..f2baa50 100644
--- a/app/todo.moon
+++ b/app/todo.moon
@@ -1,5 +1,6 @@
on_client ->
- import ReactiveVar, append, text, div, form, span, h3, a, input, textarea, button from require 'lib.component'
+ import ReactiveVar, append, text, elements from require 'lib.component'
+ import div, form, span, h3, a, input, textarea, button from elements
parent = div!
todoItem = (desc, done) ->
diff --git a/lib/component.client.moon b/lib/component.client.moon
index ee0f9ca..617deb5 100644
--- a/lib/component.client.moon
+++ b/lib/component.client.moon
@@ -48,6 +48,19 @@ class ReactiveVar
with ReactiveVar transform @value
.upstream = @subscribe (...) -> \set transform ...
+-- join = do
+-- update = (k, new) -> (old) ->
+-- with copy = { k, v for k,v in pairs old }
+-- copy[k] = new
+--
+-- (inputs) ->
+-- values = {}
+-- with ReactiveVar values
+-- for k, input in pairs inputs
+-- input = inputs[k]
+-- values[i] = input\get!
+-- input\subscribe (new) -> \transform update k, new
+
class ReactiveElement
@isinstance: (val) -> 'table' == (type val) and val.node
@@ -99,6 +112,11 @@ class ReactiveElement
if 'string' == type last
error 'cannot replace string node'
+ if child == nil
+ if last
+ @remove last
+ return
+
child = tohtml child
ok, last = pcall tohtml, last
if ok
@@ -111,16 +129,16 @@ class ReactiveElement
if 'table' == (type child) and child.destroy
child\destroy!
-with exports = {
- :ReactiveVar,
- :ReactiveElement,
- :tohtml,
- :append,
- :text,
- }
- add = (e) -> exports[e] = (...) -> ReactiveElement e, ...
-
- for e in *{'div', 'form', 'span', 'a', 'p', 'button', 'ul', 'ol', 'li', 'i', 'b', 'u', 'tt'} do add e
- for e in *{'article', 'section', 'header', 'footer', 'content'} do add e
- for e in *{'br', 'hr', 'img', 'input', 'p', 'textarea'} do add e
- for i=1,8 do add "h" .. i
+elements = setmetatable {}, __index: (name) =>
+ with val = (...) -> ReactiveElement name, ...
+ @[name] = val
+
+{
+ :ReactiveVar,
+ :ReactiveElement,
+-- :join,
+ :tohtml,
+ :append,
+ :text,
+ :elements,
+}
diff --git a/lib/component.server.moon b/lib/component.server.moon
index 54bb15c..91858c0 100644
--- a/lib/component.server.moon
+++ b/lib/component.server.moon
@@ -101,17 +101,16 @@ class ReactiveElement
b ..= "</#{@element}>"
b
-with exports = {
- :ReactiveVar,
- :ReactiveElement,
- :tohtml,
- :flush,
- :append,
- :text,
- }
- add = (e) -> exports[e] = (...) -> ReactiveElement e, ...
-
- for e in *{'div', 'form', 'span', 'a', 'p', 'button', 'ul', 'ol', 'li', 'i', 'b', 'u', 'tt'} do add e
- for e in *{'article', 'section', 'header', 'footer', 'content'} do add e
- for e in *{'br', 'hr', 'img', 'input', 'p', 'textarea'} do add e
- for i=1,8 do add "h" .. i
+elements = setmetatable {}, __index: (name) =>
+ with val = (...) -> ReactiveElement name, ...
+ @[name] = val
+
+{
+ :ReactiveVar,
+ :ReactiveElement,
+ :tohtml,
+ :flush,
+ :append,
+ :text,
+ :elements,
+}