javascript - How to prevent or debug "missing dependency links" in a RequireJS project? -
Requirements JS Dependency is expressed as partial command ... which is great ! Each module can specify exactly the dependencies that need it and no longer. Specifically, there is no need to specify linear commands between all modules.
The problem with it has been mentioned that there is a possibility to specify the circular dependency by mistake. I am now running in what you can call the opposite problem say say i have three modules, a
, b
and C
:
define ('a', [], function () {...}); Define ('b', ['a'], function () {...}); Define ('c', [], function () {...});
The actual loading order between such modules is non-deterministic. In this case there are three possible loading orders: A
→ b
→ < Code> c , & nbsp; & Nbsp; & Nbsp; a
→ c
→ b
, and c
→ a
b
. The dependency structure ensures that A
always loads before B
.
Now think, at any point, the module C
becomes A
depending on, but I forget to specify it in the module header Gone It will be very difficult to find out Two-thirds run (all orders that are equally probable) will not reveal any problem because the net chance is loaded before A
C
but in one third of cases, an error message (or worse, incorrect behavior) will occur.
If all modules return values as a single interface, then this problem will not exist. Then a very clear error message will be presented through the absence of related function parameters. But in reality, many modules add or change by reaching the global state or by modifying the state through their own dependency links. For example, this is the case with Angular JS instructions and services.
Question: What is a good way to prevent this situation from occurring or to debug it?
The answer given by Louis, I think, is to have 'proper' ways to go about this for big projects with harsh test practices. But I was looking for something easy. For example:
- A coding conference that guarantees reasonable dependencies by construction
- A device that runs all possible loading orders and then checks that the resulting state Are similar
Design your unit tests so that they start with the state where No modules exist, and do not load the entire app but only the module under the test Loading of the module will load its dependence. If one dependency was forgotten, the tests would fail.
Comments
Post a Comment