What are the common solutions for making clean id space in a SPA?

后端 未结 7 2194
感情败类
感情败类 2021-02-14 05:05

Situation: several developers working remotely on different section/modules of a SPA. As a result they may accidentally introduce HTML elements with the same id. W

7条回答
  •  猫巷女王i
    2021-02-14 05:30

    Give each developer (or module) or unique id-prefix.

    For instance, if developer X is developing a module Y, his prefix should be one of x_, y_ or xy_.
    Assuming x_ was picked, IDs created by him would look like x_foo, x_bar, x_thing etc.

    Advantages:

    1. Avoids colliding IDs (obviously).

    2. While integrating modules, the IDs clearly indicate where they belong.
      This provides improved readability, and that is pristine!!

    3. Writing x_something is irritating enough to avoid overindulgence in ID usage.
      At the same time, it is not so irritating that no one will use them.

    Disadvantages:

    1. It'll make at least some developers unhappy. (Some are less flexible than others.)
      A possible remedy is to ask them to change IDs to the x_ form,
      only towards the end of development, just before integration.
      Until then, they may use prefix-less ID names.

    2. Some modules depend on other modules. Before integration,
      appropriate ID names must be shared and correctly used.
      While this may take some additional time, it would (hopefully) be worth it.

提交回复
热议问题