chore: Updating final Attributes docs for v3
This commit is contained in:
parent
80a3dd1a2c
commit
e298d14b8f
12 changed files with 220 additions and 93 deletions
|
@ -1,24 +1,27 @@
|
|||
---
|
||||
title: setIfUnset()
|
||||
title: Attributes.setIfUnset()
|
||||
---
|
||||
|
||||
The `Attributes.setIfUnset()` method sets the attribute identified by `key` to
|
||||
value `value` but only if it's currently unset (`undefined`).
|
||||
|
||||
## Signature
|
||||
|
||||
```js
|
||||
Attributes attributes.setIfUnset(string key, string value)
|
||||
```
|
||||
|
||||
Sets the attribute identified by `key` to value `value` but only if it's currently unset (`undefined`).
|
||||
|
||||
<Tip>
|
||||
|
||||
This will never overwrite any value and thus is a safe way to set attributes
|
||||
|
||||
</Tip>
|
||||
## Example
|
||||
|
||||
```js
|
||||
let { Path, paths } = part.shorthand();
|
||||
const attr = new Attributes()
|
||||
.setIfUnset('class', 'classA')
|
||||
.setIfUnset('class', 'classB')
|
||||
|
||||
// This will render as: class="classA"
|
||||
paths.demo = new Path();
|
||||
paths.demo.attributes.set('class', 'classA');
|
||||
paths.demo.attributes.setIfUnset('class', 'classB');
|
||||
const class = attr.get('class')
|
||||
// class now holds: "classA"
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
This will never overwrite any value and thus is a safe way to set attributes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue