File tree 2 files changed +41
-3
lines changed
2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 52
52
Absolute URL
53
53
``ABSOLUTE_PATH/my-module.js``
54
54
"""
55
+
56
+ IDOM_FEATURE_INDEX_AS_DEFAULT_KEY = _option .Option (
57
+ "IDOM_FEATURE_INDEX_AS_DEFAULT_KEY" ,
58
+ default = False ,
59
+ mutable = False ,
60
+ validator = lambda x : bool (int (x )),
61
+ )
62
+ """A feature flag for using the index of a sibling element as its default key
63
+
64
+ In a future release this flag's default value will be set to true, and after that, this
65
+ flag willbe removed entirely and the indices will always be the default key.
66
+
67
+ For more information on changes to this feature flag see: https://github.com/idom-team/idom/issues/351
68
+ """
69
+
70
+ if not IDOM_FEATURE_INDEX_AS_DEFAULT_KEY .get (): # pragma: no cover
71
+ from warnings import warn
72
+
73
+ warn (
74
+ (
75
+ "In a future release 'IDOM_FEATURE_INDEX_AS_DEFAULT_KEY' will be turned on "
76
+ "by default. For more information on changes to this feature flag, see: "
77
+ "https://github.com/idom-team/idom/issues/351"
78
+ ),
79
+ UserWarning ,
80
+ )
Original file line number Diff line number Diff line change 21
21
from jsonpatch import apply_patch , make_patch
22
22
from typing_extensions import TypedDict
23
23
24
- from idom .config import IDOM_DEBUG_MODE
24
+ from idom .config import IDOM_DEBUG_MODE , IDOM_FEATURE_INDEX_AS_DEFAULT_KEY
25
25
26
26
from .component import AbstractComponent
27
27
from .events import EventHandler
@@ -453,7 +453,7 @@ async def get(self) -> AbstractComponent:
453
453
def _process_child_type_and_key (
454
454
children : List [Any ],
455
455
) -> Iterator [Tuple [Any , int , Any ]]:
456
- for child in children :
456
+ for index , child in enumerate ( children ) :
457
457
if isinstance (child , dict ):
458
458
child_type = _DICT_TYPE
459
459
key = child .get ("key" )
@@ -466,11 +466,23 @@ def _process_child_type_and_key(
466
466
key = None
467
467
468
468
if key is None :
469
- key = object ( )
469
+ key = _default_key ( index )
470
470
471
471
yield (child , child_type , key )
472
472
473
473
474
+ if IDOM_FEATURE_INDEX_AS_DEFAULT_KEY .get ():
475
+
476
+ def _default_key (index : int ) -> Any : # pragma: no cover
477
+ return index
478
+
479
+
480
+ else :
481
+
482
+ def _default_key (index : int ) -> Any :
483
+ return object ()
484
+
485
+
474
486
# used in _process_child_type_and_key
475
487
_DICT_TYPE = 1
476
488
_COMPONENT_TYPE = 2
You can’t perform that action at this time.
0 commit comments