From 416af672c415341b35aec9c99428324b2265419d Mon Sep 17 00:00:00 2001 From: s-ol Date: Sat, 27 Oct 2018 23:28:38 +1100 Subject: infinite table for lib.component --- lib/component.client.moon | 44 +++++++++++++++++++++++++++++++------------- lib/component.server.moon | 27 +++++++++++++-------------- 2 files changed, 44 insertions(+), 27 deletions(-) (limited to 'lib') 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 ..= "" 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, +} -- cgit v1.2.3