Fix localStore set to a function that fetches pre-executed backend calls
This commit is contained in:
parent
911e64a6ae
commit
076cda8008
@ -6,20 +6,19 @@
|
||||
<style>%css%</style>
|
||||
<script type="module" defer>
|
||||
import View from '/js/views/%canonicalViewName%.js';
|
||||
import {locals} from '/js/stores.js';
|
||||
import * as stores from '/js/stores.js';
|
||||
const localStore = stores[Object.keys(stores)[0]].locals;
|
||||
|
||||
locals.set(%locals%);
|
||||
const locals = %locals%;
|
||||
localStore.set((key, args) => {
|
||||
return locals[args ?
|
||||
`'${key}', \`${args}\``
|
||||
: `'${key}'`];
|
||||
});
|
||||
|
||||
new View({
|
||||
hydrate: true,
|
||||
target: document.body,
|
||||
props: {
|
||||
locals: (key, args) => {
|
||||
return locals[args ?
|
||||
`'${key}', \`${args}\``
|
||||
: `'${key}'`];
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
@ -221,7 +221,7 @@ export default class SvelteViewEngine extends ViewEngine {
|
||||
logger.info(canonicalName + ' > ', 'Replacing backend calls');
|
||||
|
||||
// Skip replace if there is no swaf export
|
||||
if (!code.match(/export[ \n]+let[ \n]+locals[ \n]*=[ \n]*{[ \n]*}/)) {
|
||||
if (!code.match(/import[ \n]+\{[ \n]*locals[ \n]*\}[ \n]+from[ \n]+["'](\.\.\/)+ts\/stores\.js["']/)) {
|
||||
return {
|
||||
backendCalls: [],
|
||||
code: code,
|
||||
@ -296,7 +296,12 @@ export default class SvelteViewEngine extends ViewEngine {
|
||||
// Load locals into locals store
|
||||
const localsModulePath = "../../build/ts/stores.js";
|
||||
const localsModule = await import(localsModulePath);
|
||||
localsModule.locals.set(ViewEngine.getGlobals());
|
||||
const locals = ViewEngine.getGlobals();
|
||||
localsModule.locals.set((key: string, args: string) => {
|
||||
return locals[args ?
|
||||
`'${key}', \`${args}\``
|
||||
: `'${key}'`];
|
||||
});
|
||||
|
||||
// Load module and render
|
||||
return requireFromString(svelteSsr.js.code, file + nanoid() + '.js').default.render();
|
||||
|
Loading…
Reference in New Issue
Block a user