fix: stabilize runtime follow-up regressions
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
:sig
|
||||
bool DTree::has(String s) const
|
||||
|
||||
:params
|
||||
s : child key to test
|
||||
return value : true when the node is map-shaped and contains the key
|
||||
|
||||
:see
|
||||
>types
|
||||
0_DTree
|
||||
get_by_path
|
||||
each
|
||||
is_array
|
||||
|
||||
:content
|
||||
Tests whether a map-shaped `DTree` contains a child key, without creating it. This is a read accessor: it is `const`, never creates or modifies nodes, and dereferences internal references automatically.
|
||||
|
||||
Returns `false` for scalar nodes and for missing keys.
|
||||
|
||||
This matters because `operator[]` creates missing entries, exactly like `std::map`. Use `has()` (or `get_by_path()`) when you only want to look:
|
||||
|
||||
```cpp
|
||||
if(context.props.has("avatar"))
|
||||
print(component("components/basic/avatar", context.props["avatar"], context));
|
||||
```
|
||||
|
||||
`has()` only checks one level. For nested checks, combine with `get_by_path()`:
|
||||
|
||||
```cpp
|
||||
bool configured = context.cfg.get_by_path("mail/smtp").is_array();
|
||||
```
|
||||
|
||||
## Related Concepts
|
||||
|
||||
- PHP: `array_key_exists()` / `isset()`
|
||||
- JavaScript: `Object.hasOwn(obj, key)` / `key in obj`
|
||||
Reference in New Issue
Block a user