separate component register and registry
This commit is contained in:
parent
1e59e4afc1
commit
5fd8aca996
12
src/index.js
12
src/index.js
|
@ -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
|
||||
Registery();
|
||||
// define global components here
|
||||
const registry = {
|
||||
'hello-riot': HelloRiot
|
||||
};
|
||||
|
||||
// register global components
|
||||
Register(registry);
|
||||
|
|
|
@ -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;
|
|
@ -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
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue