-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update methods.md #1482
base: main
Are you sure you want to change the base?
Update methods.md #1482
Conversation
fix potentially misguiding instruction
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@msqaddura mhm 🤔 I am not sure if this makes sense, do you have a concrete example? |
maybe first let me explain myself. to be sure i understand it correctly
https://stackblitz.com/edit/stencil-demo-itm9py?file=src%2Fwith-method.tsx,src%2Findex.html import { h, Component, Host, State, Method } from '@stencil/core';
@Component({
tag: 'with-method',
shadow: true,
})
export class WithMethod {
@State() text = '';
@State() counter = 0;
@Method() // Method is needed to expose the function
async setTextFromOutside(text: string) {
this.text = text;
}
// same functionality can be achieved without @Method
private setTextWithin(text: string) {
this.text = text;
}
onClick() {
this.counter += 1;
this.setTextWithin('Called Within!'); // this call can be private
this.text = 'Called Within!'; //we can access name from here, no need for setText
}
render() {
return (
<Host>
<button onClick={() => this.onClick()}>Click me</button>
</Host>
);
}
}
@Component({
tag: 'method-caller',
shadow: true,
})
export class MethodCaller {
onClick() {
const target = document.querySelector('with-method')!;
target.setTextFromOutside('Called Outside!');
// target.setTextWithin("Error"); //this is not going to work as it is not exposed via @Method()
}
render() {
return (
<Host>
<button onClick={() => this.onClick()}>Click me</button>
</Host>
);
}
} Overall, maybe it is not that important but would be good to explain the intent of the |
it seems what we want to say is that; it is callable from outside, not directly from the element (component).
though they can be called directly but the following sentence "i.e. they are intended to be callable from the outside!"
states otherwise