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

Commit

Permalink
feat: compute init & state
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Feb 8, 2021
1 parent ec1bea6 commit 2e0f59f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/core/directives/for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const forDirective = ({ el, data, state, node }: DirectiveProps) => {

const cleanedDeps = removeDupesFromArray([...data.deps, ...deps]);

// Update deps for directive
node!.deps = cleanedDeps;
node!.directives.for.deps = cleanedDeps;
}
Expand Down
19 changes: 9 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ export const init = (element: HTMLElement | Document = document): void => {
(el) => getCustomProp(el as HTMLElement, '__l') === undefined
);

for (const el of uninitializedComponents) {
for (let el of uninitializedComponents) {
const stateExpression = el.getAttribute(stateDirective);
const initExpression = el.getAttribute(initDirective);

try {
// Parse state from state expression
const state = new Function(`return ${stateExpression || '{}'}`);
const init = initExpression ? new Function(`return ${initExpression}`) : undefined;
component(state()).mount(el as HTMLElement);
if (init) init();
} catch (err) {
console.warn(`Lucia Error: "${err}"\n\nExpression: "${stateExpression}"\nElement:`, el);
}
// Parse state from state expression
const state = computeExpression(`${stateExpression || '{}'}`, el as HTMLElement, true)({});
component(state).mount(el as HTMLElement);

const init = initExpression
? computeExpression(`${initExpression}`, el as HTMLElement, true)
: undefined;
if (init) init(state);
}
};

0 comments on commit 2e0f59f

Please # to comment.