Path: csiph.com!aioe.org!news.mb-net.net!open-news-network.org!.POSTED.196.236.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: A simpler DOM in JS Date: Mon, 05 Feb 2018 11:19:18 +0100 Organization: PointedEars Software (PES) Lines: 104 Message-ID: <2311948.Lt9SDvczpP@PointedEars.de> References: <3087438.QJadu78ljV@PointedEars.de> <20800614.6Emhk5qWAg@PointedEars.de> <1fcf518b-5771-46ba-885d-3565ece3ca42@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="196.236.197.178.dynamic.wless.lssmb00p-cgnat.res.cust.swisscom.ch:178.197.236.196"; logging-data="12172"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.2 X-User-ID: U2FsdGVkX1/569gvNAu0b6Mtl7m3/UFbIekJkBn2oLqaABdnOl3SFQ== X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Thomas 'PointedEars' Lahn wrote: >> [...] >> Supplemental: >> >> 1. Add 1 for equivalence :) >> >> 2. Learning Android app development recently (again) has reminded me of >> a complementary approach: the possibility to maintain pure layout >> (XML) markup and create (widget) object( tree)s from it. > > The ghost of XSLT+XML come back to haunt us? You do not know what you are talking about. XSLT rulez (see the FAQ). But I was not referring to that. Rather, in Android app development, XML layouts are “inflated” into widget object hierarchies. For example: @Override public ArticleViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { Context context = viewGroup.getContext(); int layoutIdForListItem = R.layout.selector_list_item; LayoutInflater inflater = LayoutInflater.from(context); boolean shouldAttachToParentImmediately = false; View view = inflater.inflate(layoutIdForListItem, viewGroup, shouldAttachToParentImmediately); ArticleViewHolder viewHolder = new ArticleViewHolder(view); return viewHolder; } Then there is a file res/layout/selector_list_item.xml that contains the layout for a list item. It looks like this: -------------------------------------------------------------------------- […] -------------------------------------------------------------------------- IMHO, that approach produces very clean code¹. It could be used in ECMAScript-based Web applications as well. That is, the *validateable* markup defines the layout, script code reads the markup and converts it to description objects, and other script code produces a document fragmnt with elements having specific behaviors (widgets). The layout in XML allows to design it with a graphical editor as well (indeed, XSLT could be used to make SVG out of it) almost independent of the final presentation. The intermediary step would allow to adapt or entirely build the layout in script code without having to deal with the details of the DOM. ______ ¹ The above can still be improved; it is exercise code where the student is supposed to replace all hard-coded values with resource references for achieving a unified layout throughout all “activities” of the app. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.