admin管理员组文章数量:1414945
The requirement of the project is to separate DOM from logic in different files.
Thus, I have these files:
default.js
import { submitForm } from './logic'
function displayTaskForm(key) {
// function create form HTML content with btn submit.
submitForm(addTaskbtn, key);
return form;
}
export { displayTable };
logic.js
import { displayTable } from './default';
const submitForm = (btn, key) => {
// Adds event listener to add input to the table && local storage
displayTable(key) // shows the table content including recent input
return btn;
}
export { submitForm };
And I have these errors:
default.js
1:1 error Dependency cycle detected import/no-cycle
logic.js
1:1 error Dependency cycle detected import/no-cycle
Could you advise how I could solve this issue? the problem is I have to split my DOM from the logic part. I don't see a way to link creating DOM based on if statement results without linking both files with exporting & importing functions to each other.
Here is the original repository link
The requirement of the project is to separate DOM from logic in different files.
Thus, I have these files:
default.js
import { submitForm } from './logic'
function displayTaskForm(key) {
// function create form HTML content with btn submit.
submitForm(addTaskbtn, key);
return form;
}
export { displayTable };
logic.js
import { displayTable } from './default';
const submitForm = (btn, key) => {
// Adds event listener to add input to the table && local storage
displayTable(key) // shows the table content including recent input
return btn;
}
export { submitForm };
And I have these errors:
default.js
1:1 error Dependency cycle detected import/no-cycle
logic.js
1:1 error Dependency cycle detected import/no-cycle
Could you advise how I could solve this issue? the problem is I have to split my DOM from the logic part. I don't see a way to link creating DOM based on if statement results without linking both files with exporting & importing functions to each other.
Here is the original repository link
Share Improve this question edited Jun 6, 2021 at 5:36 Sarvar Khalimov asked Jun 6, 2021 at 4:12 Sarvar KhalimovSarvar Khalimov 5251 gold badge7 silver badges11 bronze badges1 Answer
Reset to default 2I think the issue might be rooted in where you've decided to draw the line between UI-related code, and logic. Here's how I draw it:
UI: anything that touches the DOM - this includes creating elements, attaching event listeners, etc. The UI can call out to logic for help.
logic: A bunch of helper functions (maybe classes if you're into that), which are mostly pure. These are functions in which the UI can delegate difficult tasks to. A DOM element should never be seen by this logic module. The logic should never depend upon a specific UI (so it shouldn't ever import the UI).
Another way to think of it - if I were to toss your current UI file and build a CLI version of your program that ran in node, would I have to make any changes to your logic file? If so, then your logic is touching UI-specific things it shouldn't be touching.
It's a little hard to tell, looking at your examples what's going on in your specific scenario, and your GitHub link currently doesn't have any code in it. But, hopefully, these guiding principles should help out. It could be that this circular dependency is really just showing that something that currently sets in the logic file needs to be partially or entirely moved to the UI file.
If you find that most to all of your code qualifies as UI-related code, then it could be that you need to work on finding and extracting out the pure parts of a chunk of logic and making that piece of logic able to stand by itself and be reusable in other contexts. Or, it could be that your particular webpage mostly deals with logic that's highly coupled with the UI.
本文标签: javascriptESLint error Dependency cycle detected importnocycleStack Overflow
版权声明:本文标题:javascript - ESLint error: Dependency cycle detected importno-cycle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745188716a2646807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论