Skip to content

Commit 5042c51

Browse files
refactor(directives.js): Suppress console warnings and improve code readability
Clean up directives.js by suppressing console warnings and improving code readability with better parameter naming and arrow functions. Changes: - Add underscore prefix to unused _prevVnode parameter to suppress warnings - Comment out console.warn and console.log statements - Refactor map and forEach callbacks to use arrow functions - Improve code formatting and readability This reduces console noise during development and improves code maintainability.
1 parent 3da0b5b commit 5042c51

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/boot/directives.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
export default ({ app }) => {
22
app.directive('colorize', {
3-
created (el, binding, vnode, prevVnode) {
4-
console.warn('🚀 ~ file: directives.js ~ line 4 ~ created ~ el', el);
3+
// added underscore to the _prevVnode parameter to suppress the warning
4+
created (el, binding, vnode, _prevVnode) {
5+
// console.warn('🚀 ~ file: directives.js ~ line 4 ~ created ~ el', el);
56
const { value } = binding;
6-
const wordsAndColors = value.map(item => {
7+
const wordsAndColors = value.map((item) => {
78
const [word, color] = item.split('::');
89
return {
910
word,
1011
color,
1112
};
1213
});
1314
let text = vnode.el.innerHTML || '';
14-
console.log('🚀 ~ file: directives.js ~ line 14 ~ created ~ text', text);
15-
wordsAndColors.forEach(item => {
16-
console.warn('item', item);
15+
// console.log('🚀 ~ file: directives.js ~ line 14 ~ created ~ text', text);
16+
wordsAndColors.forEach((item) => {
17+
// console.warn('item', item);
1718
const regex = new RegExp(item.word, 'gi');
18-
console.warn(regex);
19-
text = text.replace(regex, `<span style="color: ${item.color}">${item.word}</span>`);
19+
// console.warn(regex);
20+
text = text.replace(
21+
regex,
22+
`<span style="color: ${item.color}">${item.word}</span>`,
23+
);
2024
});
2125
console.warn('text', text);
2226
el.innerHTML = text;
@@ -26,7 +30,7 @@ export default ({ app }) => {
2630
// called when the bound element's parent component
2731
// and all its children are mounted.
2832
mounted () {
29-
console.warn('mounted');
33+
// console.warn('mounted');
3034
},
3135
// called before the parent component is updated
3236
beforeUpdate () {},
@@ -37,6 +41,5 @@ export default ({ app }) => {
3741
beforeUnmount () {},
3842
// called when the parent component is unmounted
3943
unmounted () {},
40-
4144
});
4245
};

0 commit comments

Comments
 (0)