aboutsummaryrefslogtreecommitdiffstats
path: root/lib/component.server.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-01 09:01:49 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-01 09:01:49 +0000
commitfc181b154fb3f5cdefcf72c2a496b5b14f274e79 (patch)
tree5b4cfbebb4760fba68161265f07826b55206c311 /lib/component.server.moon
parentREHYDRATION (diff)
parentfaster time to first render (diff)
downloadmmm-fc181b154fb3f5cdefcf72c2a496b5b14f274e79.tar.gz
mmm-fc181b154fb3f5cdefcf72c2a496b5b14f274e79.zip
Merge branch 'root-mmmfs'
Diffstat (limited to 'lib/component.server.moon')
-rw-r--r--lib/component.server.moon20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/component.server.moon b/lib/component.server.moon
index 85d97eb..0026d32 100644
--- a/lib/component.server.moon
+++ b/lib/component.server.moon
@@ -1,5 +1,8 @@
import opairs from require 'lib.ordered'
+void_tags = { 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr' }
+void_tags = { t,t for t in *void_tags }
+
-- convert anything to HTML string
-- val must be one of:
-- * MMMElement (have a .render method that returns a string)
@@ -97,17 +100,28 @@ class ReactiveElement
tmp ..= "#{kk}: #{vv}; "
v = tmp
b ..= " #{k}=\"#{v}\""
- b ..= ">" .. table.concat @children, ''
- b ..= "</#{@element}>"
- b
+
+ if void_tags[@element]
+ assert #@children == 0, "void tag #{element} cannot have children!"
+ b .. ">"
+ else
+ b .. ">"
+ b ..= ">" .. table.concat @children, ''
+ b ..= "</#{@element}>"
+ b
elements = setmetatable {}, __index: (name) =>
with val = (...) -> ReactiveElement name, ...
@[name] = val
+get_or_create = (elem, id, ...) ->
+ with ReactiveElement elem, ...
+ \set 'id', id
+
{
:ReactiveVar,
:ReactiveElement,
+ :get_or_create,
:tohtml,
:flush,
:append,