Skip to content

Commit 3dccd5f

Browse files
committed
Add custom element with method
1 parent 39ce56b commit 3dccd5f

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright 2017 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
class CEWithMethods extends HTMLElement {
19+
20+
test() {
21+
this.innerText = 'Success';
22+
}
23+
24+
connectedCallback() {
25+
this.test();
26+
}
27+
28+
}
29+
30+
customElements.define('ce-with-methods', CEWithMethods);

libraries/angular/src/basic-tests.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
ComponentWithProperties,
2828
ComponentWithUnregistered,
2929
ComponentWithImperativeEvent,
30-
ComponentWithDeclarativeEvent
30+
ComponentWithDeclarativeEvent,
31+
ComponentWithMethods
3132
} from "./components";
3233

3334
beforeEach(function() {
@@ -40,7 +41,8 @@ beforeEach(function() {
4041
ComponentWithProperties,
4142
ComponentWithUnregistered,
4243
ComponentWithImperativeEvent,
43-
ComponentWithDeclarativeEvent
44+
ComponentWithDeclarativeEvent,
45+
ComponentWithMethods
4446
],
4547
schemas: [CUSTOM_ELEMENTS_SCHEMA]
4648
});
@@ -146,6 +148,13 @@ describe("basic support", function() {
146148
let data = wc.str || wc.getAttribute("str");
147149
expect(data).to.eql("Angular");
148150
});
151+
152+
it('will not overwrite methods', function () {
153+
let fixture = TestBed.createComponent(ComponentWithMethods);
154+
fixture.detectChanges();
155+
let root = fixture.debugElement.nativeElement;
156+
expect(root.innerText).to.eql('Success')
157+
});
149158
});
150159

151160
describe("events", function() {

libraries/angular/src/components.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'ce-without-children';
2727
import 'ce-with-children';
2828
import 'ce-with-properties';
2929
import 'ce-with-event';
30+
import 'ce-with-methods';
3031

3132
@Component({
3233
template: `
@@ -105,6 +106,15 @@ export class ComponentWithProperties {
105106
}
106107
}
107108

109+
@Component({
110+
template: `
111+
<div>
112+
<ce-with-methods [test]="true"></ce-with-methods>
113+
</div>
114+
`
115+
})
116+
export class ComponentWithMethods {}
117+
108118
@Component({
109119
template: `
110120
<div>

libraries/react/src/basic-tests.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
ComponentWithUnregistered,
3030
ComponentWithImperativeEvent,
3131
ComponentWithDeclarativeEvent,
32+
ComponentWithMethods,
3233
} from "./components";
3334

3435
// Setup the test harness. This will get cleaned out with every test.
@@ -198,6 +199,19 @@ describe("basic support", function () {
198199
expect(data).to.eql("React");
199200
});
200201

202+
it('will not overwrite methods', function () {
203+
let root;
204+
render(
205+
<ComponentWithMethods
206+
ref={(current) => {
207+
root = current;
208+
}}
209+
/>
210+
)
211+
let wc = root.wc;
212+
expect(wc.innerText).to.eql('Success');
213+
})
214+
201215
// TODO: Is it the framework's responsibility to check if the underlying
202216
// property is defined? Or should it just always assume it is and do its
203217
// usual default behavior? Preact will actually check if it's defined and

libraries/react/src/components.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'ce-without-children';
2020
import 'ce-with-children';
2121
import 'ce-with-properties';
2222
import 'ce-with-event';
23+
import 'ce-with-methods';
2324

2425
export class ComponentWithoutChildren extends Component {
2526
render() {
@@ -110,6 +111,14 @@ export class ComponentWithProperties extends Component {
110111
}
111112
}
112113

114+
export class ComponentWithMethods extends Component {
115+
render() {
116+
return <div>
117+
<ce-with-methods test ref={(el) => this.wc = el}></ce-with-methods>
118+
</div>
119+
}
120+
}
121+
113122
export class ComponentWithUnregistered extends Component {
114123
render () {
115124
const data = {

0 commit comments

Comments
 (0)