Merge pull request #770 from lowdefy/fixes

v3.20 fixes
This commit is contained in:
Sam 2021-08-20 19:12:38 +02:00 committed by GitHub
commit 88703e4f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 55 deletions

View File

@ -0,0 +1,31 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function cachedPromises(getter) {
const cache = {};
function getCachedPromise(key) {
if (cache[key]) {
return Promise.resolve(cache[key]);
}
cache[key] = getter(key);
return Promise.resolve(cache[key]);
}
return getCachedPromise;
}
export default cachedPromises;

View File

@ -17,15 +17,13 @@
import path from 'path';
import { readFile } from '@lowdefy/node-utils';
import cachedPromises from '../cachePromises';
function createReadConfigFile({ configDirectory }) {
const files = {};
async function readConfigFile(filePath) {
if (files[filePath]) return files[filePath];
const fileContent = readFile(path.resolve(configDirectory, filePath));
files[filePath] = fileContent;
return fileContent;
return readFile(path.resolve(configDirectory, filePath));
}
return readConfigFile;
return cachedPromises(readConfigFile);
}
export default createReadConfigFile;

View File

@ -26,13 +26,14 @@ Steps to fetch meta
*/
import { type as typeHelper } from '@lowdefy/helpers';
import cachedPromises from '../cachePromises';
import createFetchMetaCache from './fetchMetaCache';
import createWriteMetaCache from './writeMetaCache';
import metaLocations from './metaLocations';
import fetchMetaUrl from './fetchMetaUrl';
function createGetMeta({ blocksServerUrl, cacheDirectory, types }) {
const memoisedMeta = {};
const allMetaLocations = {
...metaLocations({ blocksServerUrl }),
...types,
@ -40,10 +41,6 @@ function createGetMeta({ blocksServerUrl, cacheDirectory, types }) {
const fetchMetaCache = createFetchMetaCache({ cacheDirectory });
const writeMetaCache = createWriteMetaCache({ cacheDirectory });
async function getMeta(type) {
if (memoisedMeta[type]) {
return memoisedMeta[type];
}
const location = allMetaLocations[type];
if (!location) {
throw new Error(
@ -57,7 +54,6 @@ function createGetMeta({ blocksServerUrl, cacheDirectory, types }) {
if (cacheMeta) {
meta = await fetchMetaCache(location);
if (meta) {
memoisedMeta[type] = meta;
return meta;
}
}
@ -65,7 +61,6 @@ function createGetMeta({ blocksServerUrl, cacheDirectory, types }) {
meta = await fetchMetaUrl({ location, type });
// TODO: implement Ajv schema check. Use testAjvSchema func from @lowdefy/ajv
if (meta && typeHelper.isString(meta.category) && meta.moduleFederation) {
memoisedMeta[type] = meta;
if (cacheMeta) {
await writeMetaCache({ location, meta });
}
@ -76,7 +71,7 @@ function createGetMeta({ blocksServerUrl, cacheDirectory, types }) {
);
}
return getMeta;
return cachedPromises(getMeta);
}
export default createGetMeta;

View File

@ -13,46 +13,46 @@
See the License for the specific language governing permissions and
limitations under the License. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Lowdefy App</title>
<link rel="manifest" href="/public/manifest.webmanifest">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Lowdefy App</title>
<link rel="manifest" href="/public/manifest.webmanifest" />
<link rel="icon" type="image/svg+xml" href="/public/icon.svg">
<link rel="icon" type="image/png" href="/public/icon-32.png">
<link rel="apple-touch-icon" href="/public/apple-touch-icon.png">
<script src="/api/dev/reload.js"></script>
<script type="text/javascript">
const jsActions = {}
const jsOperators = {}
const getMethodLoader = (scope, reference) =>
(name, method) => {
if (typeof name !== 'string') {
throw new Error(`${scope} requires a string for the first argument.`)
}
if (typeof method !== 'function') {
throw new Error(`${scope} requires a function for the second argument.`)
}
reference[name] = method;
}
window.lowdefy = {
imports: {
jsActions,
jsOperators,
},
registerJsAction: getMethodLoader('registerJsAction', jsActions),
registerJsOperator: getMethodLoader('registerJsOperator', jsOperators)
<link rel="icon" type="image/svg+xml" href="/public/icon.svg" />
<link rel="icon" type="image/png" href="/public/icon-32.png" />
<link rel="apple-touch-icon" href="/public/apple-touch-icon.png" />
<script src="/api/dev/reload.js"></script>
<script type="text/javascript">
const jsActions = {};
const jsOperators = {};
const getMethodLoader = (scope, reference) => (name, method) => {
if (typeof name !== 'string') {
throw new Error(`${scope} requires a string for the first argument.`);
}
</script>
if (typeof method !== 'function') {
throw new Error(`${scope} requires a function for the second argument.`);
}
reference[name] = method;
};
window.lowdefy = {
basePath: '',
imports: {
jsActions,
jsOperators,
},
registerJsAction: getMethodLoader('registerJsAction', jsActions),
registerJsOperator: getMethodLoader('registerJsOperator', jsOperators),
};
</script>
<!-- __LOWDEFY_APP_HEAD_HTML__ -->
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="emotion"></div>
<div id="root"></div>
<!-- __LOWDEFY_APP_BODY_HTML__ -->
</body>
</html>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="emotion"></div>
<div id="root"></div>
<!-- __LOWDEFY_APP_BODY_HTML__ -->
</body>
</html>

View File

@ -15,7 +15,6 @@
*/
const transformer = (_, obj) => {
console.log('transformer', _, obj);
const examples = {
id: 'examples',
type: 'Box',