From 03d681f91b07a2971cee25e63b0ede38b82ec5a2 Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 23 Oct 2023 17:58:23 +0200 Subject: [PATCH] Slightly better data waiting --- literal-html/module.js | 69 ++++++++++++++++++++-------------------- modules/latest-stream.js | 30 +++++++++++++++++ 2 files changed, 64 insertions(+), 35 deletions(-) create mode 100755 modules/latest-stream.js diff --git a/literal-html/module.js b/literal-html/module.js index d051ae8..75d0a60 100644 --- a/literal-html/module.js +++ b/literal-html/module.js @@ -84,9 +84,8 @@ mapping an array of objects to template includes: import noop from '../../fn/modules/noop.js'; -import Stream from '../../fn/modules/stream.js'; import element, { getInternals as Internals } from '../../dom/modules/element.js'; -/*import properties, { addLoading, removeLoading } from '../modules/properties.js';*/ +import LatestStream from '../modules/latest-stream.js'; import requestData from '../modules/request-data.js'; import TemplateRenderer from '../modules/renderer-template.js'; import print from '../modules/library/print.js'; @@ -113,39 +112,20 @@ function parseData(value) { value ; } -function resolveData(value) { - return rpath.test(value) ? - requestData(value) : - parseData(value) ; -} - -function requestDataFromSrc(template, datas, value) { - return requestData(value) - .then((data) => datas.push(data)) - .catch((e) => onerror(e, template)); -} - -function requestDataFromDataset(template, datas, dataset) { +function getDataFromDataset(dataset) { const keys = Object.keys(dataset); const values = Object.values(dataset); - //addLoading(template); - - return Promise - .all(values.map(resolveData)) - .then((values) => datas.push( - values.reduce((data, value, i) => (data[keys[i]] = value, data), {}) - )) - .catch((e) => onerror(e, template)) - //.finally(() => removeLoading(template)); + return values + .map(parseData) + .reduce((data, value, i) => (data[keys[i]] = value, data), {}) ; } // tag, template, lifecycle, properties, log export default element('