From 29d2b615dafa6f3a54910b72d303f74a97c4d822 Mon Sep 17 00:00:00 2001 From: s-ol Date: Thu, 1 Nov 2018 19:07:40 +1100 Subject: component get_or_create --- lib/component.client.moon | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/component.client.moon') diff --git a/lib/component.client.moon b/lib/component.client.moon index 6e0e8d8..ffeb084 100644 --- a/lib/component.client.moon +++ b/lib/component.client.moon @@ -136,6 +136,12 @@ class ReactiveElement if 'table' == (type child) and child.destroy child\destroy! +get_or_create = (elem, id, ...) -> + elem = (document\getElementById id) or elem + + with ReactiveElement elem, ... + \set 'id', id + elements = setmetatable {}, __index: (name) => with val = (...) -> ReactiveElement name, ... @[name] = val @@ -143,6 +149,7 @@ elements = setmetatable {}, __index: (name) => { :ReactiveVar, :ReactiveElement, + :get_or_create, -- :join, :tohtml, :append, -- cgit v1.2.3