Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
chore: simplify import proc for adhoc
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed May 23, 2021
1 parent ce37057 commit e59e9a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ content="<!DOCTYPE html>
<meta charset=\"utf-8\" />
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />
<script type=\"module\">
import { init, component } from 'lucia';
init();
import 'lucia';
</script>
</head>
<body>
Expand Down
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import component from './component';
import { COMPONENT_FLAG, DIRECTIVE_PREFIX } from '@models/generics';

export { component };

/**
* Initialize components defined in HTML with `l-state`
* @param {HTMLElement|Document} element - Root element to find uninitialized components
*/
const init = (element: HTMLElement | Document = document): void => {
export const init = (element: HTMLElement | Document = document): void => {
const stateDirective = `${DIRECTIVE_PREFIX}state`;
const componentElements = element.querySelectorAll<HTMLElement>(`[${stateDirective}]`);
const uninitializedComponents = [...componentElements].filter(
Expand All @@ -21,8 +23,4 @@ const init = (element: HTMLElement | Document = document): void => {
});
};

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => init());
}

export { init, component };
document.addEventListener('DOMContentLoaded', () => init());

0 comments on commit e59e9a9

Please sign in to comment.