1
0
Fork 0

chore: Updating final Attributes docs for v3

This commit is contained in:
Joost De Cock 2022-09-29 19:01:10 +02:00
parent 80a3dd1a2c
commit e298d14b8f
12 changed files with 220 additions and 93 deletions

View file

@ -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