-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add working with decorators doc and updated api-report markdown (#7012)
# Pull Request ## π Description This change adds a document on working without decorators. ### π« Issues Closes #6376 ## β Checklist ### General <!--- Review the list and put an x in the boxes that apply. --> - [x] I have included a change request file using `$ npm run change` - [ ] I have added tests for my changes. - [x] I have tested my changes. - [x] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/master/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/master/CODE_OF_CONDUCT.md#our-standards) for this project.
- Loading branch information
Showing
8 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@microsoft-fast-element-ffdf0a73-daa4-462a-bc2f-60a25ce2066f.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "none", | ||
"comment": "Add working with decorators doc and updated api-report markdown", | ||
"packageName": "@microsoft/fast-element", | ||
"email": "[email protected]", | ||
"dependentChangeType": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
sites/website/src/docs/advanced/working-without-decorators.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
id: working-without-decorators | ||
title: Working without Decorators | ||
sidebar_label: Working without Decorators | ||
keywords: | ||
- decorators | ||
--- | ||
|
||
Most of our documented examples include the use of TypeScript decorators. However, as decorators are an unimplemented feature in JavaScript, using them may not be right for your project. See [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for details on our implementation. | ||
|
||
The static `definition` accepts the same configuration options as the `@attr` decorator. For example, to bind a property name that is different from an attribute name: | ||
|
||
```javascript | ||
import { FASTElement, html, css } from '@microsoft/fast-element'; | ||
|
||
export class MyElement extends FASTElement { | ||
static definition = { | ||
name: 'my-element', | ||
template: html`<div>${(x) => x.count}</div>`, | ||
styles: css`div { background: red }`, | ||
attributes: [ | ||
'count', | ||
], | ||
}; | ||
} | ||
|
||
FASTElement.define(MyElement); | ||
``` | ||
|
||
```html | ||
<my-element count="42"> | ||
``` | ||
|
||
This accepts the same configuration options as the `@attr` so for example to bind a property name that is different from an attribute name: | ||
|
||
```javascript | ||
import { FASTElement, html, css } from '@microsoft/fast-element'; | ||
|
||
export class MyElement extends FASTElement { | ||
static definition = { | ||
name: 'my-element', | ||
template: html`<div>${(x) => x.currentCount}</div>`, | ||
styles: css`div { background: red }`, | ||
attributes: [ | ||
{ | ||
attribute: 'current-count', | ||
property: 'currentCount' | ||
}, | ||
], | ||
}; | ||
|
||
currentCount = 42; | ||
} | ||
|
||
FASTElement.define(MyElement); | ||
``` | ||
|
||
If you need to add a converter to your attribute: | ||
|
||
```javascript | ||
import { FASTElement, html, css } from '@microsoft/fast-element'; | ||
|
||
const converter = { | ||
toView: (value) => { | ||
return value / 2; | ||
}, | ||
fromView: (value) => { | ||
return value / 2; | ||
}, | ||
}; | ||
|
||
export class MyElement extends FASTElement { | ||
static definition = { | ||
name: 'my-element', | ||
template: html`<div>${(x) => x.currentCount}</div>`, | ||
styles: css`div { background: red }`, | ||
attributes: [ | ||
{ | ||
attribute: 'current-count', | ||
property: 'currentCount', | ||
converter | ||
}, | ||
], | ||
}; | ||
|
||
currentCount = 42; | ||
} | ||
|
||
FASTElement.define(MyElement); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters