diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2018-07-01 23:09:37 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2018-07-01 23:09:37 +0000 |
| commit | d6fd0bf7834a284b61e7275ebb07b718458f075b (patch) | |
| tree | 06db4faf87cd2a6019b3e660146a979aac02c954 | |
| parent | update packages (diff) | |
| download | mmm-d6fd0bf7834a284b61e7275ebb07b718458f075b.tar.gz mmm-d6fd0bf7834a284b61e7275ebb07b718458f075b.zip | |
export asnode, append helpers
| -rw-r--r-- | app/component.moon | 13 | ||||
| -rw-r--r-- | app/test_component.moon | 10 |
2 files changed, 19 insertions, 4 deletions
diff --git a/app/component.moon b/app/component.moon index 86458bd..f0bc77f 100644 --- a/app/component.moon +++ b/app/component.moon @@ -18,6 +18,13 @@ asnode = (val) -> else error "not a Node: #{val}, #{type val}" +-- shorthand to append elements to body +-- see #asnode for permitted values +append = (val) -> document.body\appendChild asnode val + +-- shorthand to form a text node from strings +text = (...) -> document\createTextNode table.concat { ... }, ' ' + class ReactiveVar @isinstance: (val) -> 'table' == (type val) and val.subscribe @@ -102,15 +109,15 @@ class ReactiveElement if 'table' == (type child) and child.destroy child\destroy! -text = (...) -> document\createTextNode table.concat { ... }, ' ' - with exports = { :ReactiveVar, :ReactiveElement, + :asnode, + :append, :text, } add = (e) -> exports[e] = (...) -> ReactiveElement e, ... - for e in *{'div', 'form', 'span', 'a', 'p', 'button', 'ul', 'li', 'i', 'b', 'u', 'tt'} do add e + for e in *{'div', 'form', 'span', 'article', 'a', 'p', 'button', 'ul', 'li', 'i', 'b', 'u', 'tt'} do add e for e in *{'br', 'img', 'input', 'p', 'textarea'} do add e for i=1,8 do add "h" .. i diff --git a/app/test_component.moon b/app/test_component.moon index 8e2f95f..5298175 100644 --- a/app/test_component.moon +++ b/app/test_component.moon @@ -21,9 +21,17 @@ run_test "exports ReactiveVar, ReactiveElement", -> assert ReactiveVar, "ReactiveVar not exported" assert ReactiveElement, "ReactiveElement not exported" +run_test "exports asnode helper", -> + import asnode from require './component.moon' + assert 'function' == (type asnode), "asnode not exported" + +run_test "exports append helper", -> + import append from require './component.moon' + assert 'function' == (type append), "append not exported" + run_test "exports text helper", -> import text from require './component.moon' - assert 'function' == (type text), "ReactiveVar not exported" + assert 'function' == (type text), "text not exported" node = text 'a test string' assert (js.instanceof node, js.global.Node), "expected text to generate a Node" |
