|
2 | 2 | "MgtComponent": { |
3 | 3 | "prefix": "mgtnew", |
4 | 4 | "body": [ |
5 | | - "import { html, css, customElement, property } from 'lit-element';", |
6 | 5 | "import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';", |
7 | | - "import { MgtTemplatedComponent } from '../templatedComponent';", |
| 6 | + "import { css, customElement, html, property } from 'lit-element';", |
8 | 7 | "import { Providers } from '../../Providers';", |
9 | 8 | "import { ProviderState } from '../../providers/IProvider';", |
| 9 | + "import { MgtTemplatedComponent } from '../templatedComponent';", |
10 | 10 | "", |
| 11 | + "/**", |
| 12 | + " *", |
| 13 | + " *", |
| 14 | + " * @export", |
| 15 | + " * @class ${1}", |
| 16 | + " * @extends {MgtTemplatedComponent}", |
| 17 | + " */", |
11 | 18 | "@customElement('${1:mgt-component}')", |
12 | 19 | "export class ${2:MgtComponent} extends MgtTemplatedComponent {", |
| 20 | + " /**", |
| 21 | + " * Array of styles to apply to the element. The styles should be defined", |
| 22 | + " * using the `css` tag function.", |
| 23 | + " */", |
| 24 | + " static get styles() {", |
| 25 | + " return css`", |
| 26 | + " .title {", |
| 27 | + " color: red;", |
| 28 | + " }", |
| 29 | + " `;", |
| 30 | + " }", |
| 31 | + "", |
| 32 | + " /**", |
| 33 | + " *", |
| 34 | + " *", |
| 35 | + " * @type {string}", |
| 36 | + " * @memberof MgtComponent", |
| 37 | + " */", |
13 | 38 | " @property({", |
14 | 39 | " attribute: 'my-title',", |
15 | 40 | " type: String", |
16 | 41 | " })", |
17 | | - " myTitle: string = 'My First Component';", |
| 42 | + " public myTitle: string = 'My First Component';", |
18 | 43 | "", |
19 | 44 | " // assignment to this property will re-render the component", |
20 | 45 | " @property({ attribute: false }) private _me: MicrosoftGraph.User;", |
21 | 46 | "", |
22 | | - " attributeChangedCallback(name, oldval, newval) {", |
| 47 | + " /**", |
| 48 | + " * Synchronizes property values when attributes change.", |
| 49 | + " *", |
| 50 | + " * @param {*} name", |
| 51 | + " * @param {*} oldValue", |
| 52 | + " * @param {*} newValue", |
| 53 | + " * @memberof MgtPersonCard", |
| 54 | + " */", |
| 55 | + " public attributeChangedCallback(name, oldval, newval) {", |
23 | 56 | " super.attributeChangedCallback(name, oldval, newval);", |
24 | 57 | "", |
25 | 58 | " // TODO: handle when an attribute changes.", |
|
30 | 63 | " // }", |
31 | 64 | " }", |
32 | 65 | "", |
33 | | - " firstUpdated() {", |
| 66 | + " /**", |
| 67 | + " * Invoked when the element is first updated. Implement to perform one time", |
| 68 | + " * work on the element after update.", |
| 69 | + " *", |
| 70 | + " * Setting properties inside this method will trigger the element to update", |
| 71 | + " * again after this update cycle completes.", |
| 72 | + " *", |
| 73 | + " * * @param _changedProperties Map of changed properties with old values", |
| 74 | + " */", |
| 75 | + " public firstUpdated() {", |
34 | 76 | " Providers.onProviderUpdated(() => this.loadData());", |
35 | 77 | " this.loadData();", |
36 | 78 | " }", |
37 | 79 | "", |
| 80 | + " /**", |
| 81 | + " * Invoked on each update to perform rendering tasks. This method must return", |
| 82 | + " * a lit-html TemplateResult. Setting properties inside this method will *not*", |
| 83 | + " * trigger the element to update.", |
| 84 | + " */", |
| 85 | + " protected render() {", |
| 86 | + " $0return html`", |
| 87 | + " <div class='root'>", |
| 88 | + " <h1 class='title'>${this.myTitle}</h1>", |
| 89 | + " ${this._me ? `Hello ${this._me.displayName}` : 'Not signed in'}!", |
| 90 | + " </div>", |
| 91 | + " `;", |
| 92 | + " }", |
| 93 | + "", |
38 | 94 | " private async loadData() {", |
39 | | - " let provider = Providers.globalProvider;", |
| 95 | + " const provider = Providers.globalProvider;", |
40 | 96 | "", |
41 | 97 | " if (!provider || provider.state !== ProviderState.SignedIn) {", |
42 | 98 | " return;", |
|
45 | 101 | " // TODO: load data from the graph", |
46 | 102 | " this._me = await provider.graph.client.api('/me').get();", |
47 | 103 | " }", |
48 | | - "", |
49 | | - " static get styles() {", |
50 | | - " return css`", |
51 | | - " .title {", |
52 | | - " color: red;", |
53 | | - " }", |
54 | | - " `;", |
55 | | - " }", |
56 | | - "", |
57 | | - " render() {", |
58 | | - " $0return html`", |
59 | | - " <div class='root'>", |
60 | | - " <h1 class='title'>${this.myTitle}</h1>", |
61 | | - " ${this._me ? `Hello ${this._me.displayName}` : `Not signed in`}!", |
62 | | - " </div>", |
63 | | - " `;", |
64 | | - " }", |
65 | | - "}" |
| 104 | + "}", |
| 105 | + "" |
66 | 106 | ], |
67 | 107 | "description": "Create New Mgt Component" |
68 | 108 | } |
|
0 commit comments