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

Commit

Permalink
fix: value not returning during computation
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Feb 22, 2021
1 parent 349113b commit e8c28af
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/core/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export const isUnderListRenderScope = (el: HTMLElement): boolean => {
export const createASTNode = (el: HTMLElement, state: State): ASTNode | null => {
const [directives, deps] = collectAndInitDirectives(el, state);

// Check if there are directives
const hasDirectives = Object.keys(directives).length > 0;

// Check if there are affected props in state
const hasDepInDirectives = Object.values(directives).some(({ value }) =>
Object.keys(state).some((prop) => expressionPropRE(prop).test(value))
);
Expand Down Expand Up @@ -55,7 +52,7 @@ export const collectAndInitDirectives = (
const deps: string[] = propsInState.filter((prop) => {
const hasDep = expressionPropRE(prop).test(String(value));

// Compare toString value of function
// Check for dependencies inside functions
if (typeof state[prop] === 'function' && hasDep) {
const depsInFunction = propsInState.filter((p) =>
expressionPropRE(p).test(String(state[prop]))
Expand Down
3 changes: 1 addition & 2 deletions src/core/directives/for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export const forDirective = ({ el, data, state, node }: DirectiveProps) => {

if (!marker) {
adjustDeps(ast, data.deps, node, 'for');
setElementCustomProp(el, '__l_for_ast', compile(el, state));
}

render(getElementCustomProp(el, '__l_for_ast'), directives, state, node.deps);
render(compile(el, state), directives, state, node.deps);
};
2 changes: 1 addition & 1 deletion src/core/utils/computeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const computeExpression = (
const value = state[expression];
if (value) {
// @ts-expect-error
typeof value === 'function' ? state[expression]() : value;
return typeof value === 'function' ? state[expression]() : value;
} else {
const emit = (name: string, options?: CustomEventInit, dispatchGlobal: boolean = true) => {
const event = new CustomEvent(name, options);
Expand Down

0 comments on commit e8c28af

Please # to comment.