Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bind hooks never call #3

Closed
wants to merge 1 commit into from
Closed

fix: bind hooks never call #3

wants to merge 1 commit into from

Conversation

NavOrange
Copy link

close #2

Comment on lines +10 to +12
export default function (observer, hook = {}) {
// Before Hook
typeof hook === "object" && typeof before === "function" && before();
hook.before?.();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes using the optional chaining operator and default parameters may not be certainly better. It helps the developer but is not very friendly for compiling(See below).

var _hook$before, _hook$after;

// Before Hook
(_hook$before = hook.before) === null || _hook$before === void 0 ? void 0 : _hook$before.call(hook);

// ...

// After Hook
(_hook$after = hook.after) === null || _hook$after === void 0 ? void 0 : _hook$after.call(hook);

IMO, it's enough to use the && operator. The bundled script will also be relatively tighter and smaller.

// Before Hook
hook && typeof hook.before === 'function' && hook.before();

// ...

// After Hook
hook && typeof hook.after === 'function' && hook.after();

Lastly, feel free to try it with an online babel compiler or just in this project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your opinion, I will take your advice.

@stevenlei
Copy link
Contributor

Thank you @Shuhua95 , we will take @plainheart 's advice on the coding style.

@stevenlei stevenlei closed this Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] before 还未从 hook 中拿出就进行判断了
3 participants