separate component register and registry

This commit is contained in:
Geoff Doty 2022-07-29 00:15:07 -04:00
parent 1e59e4afc1
commit 5fd8aca996
3 changed files with 32 additions and 24 deletions

View File

@ -1,4 +1,10 @@
import Registery from './js/registery.js'; import {Register} from './js/register.js';
import HelloRiot from './components/hello-riot/hello-riot.riot';
// globally register all pages // define global components here
Registery(); const registry = {
'hello-riot': HelloRiot
};
// register global components
Register(registry);

23
src/js/register.js Normal file
View File

@ -0,0 +1,23 @@
import {register, mount} from 'riot';
/**
* Register Global Components
*
* helper that registers and mounts global components
* via an object registry
*
* @param {Object} registry key:value object registry
*/
export function Register(registry = {}) {
Object.entries(registry).map(([name, component]) => {
register(name, component);
mount(name);
return {
name,
component
}
});
}
export default Register;

View File

@ -1,21 +0,0 @@
import {register, mount} from 'riot';
import HelloRiot from '../pages/hello-riot/hello-riot.riot';
/*
Add Global Pages to registry
*/
const Registry = {
'hello-riot': HelloRiot
};
export default () => {
Object.entries(Registry).map(([name, component]) => {
register(name, component);
mount(name);
return {
name,
component
}
});
}