Last active
June 14, 2019 19:16
-
-
Save jcfranco/99f37b2c084700d96662b7809ddd5788 to your computer and use it in GitHub Desktop.
Boilerplate draft for calcite-app-components
This file contains hidden or 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
/* | |
Enforceable by `component-member-order` rule (https://github.com/natemoo-re/tslint-stencil/blob/5aa7cfc5e3b627e67cd42ea3fbe7b8394fd14730/docs/component-member-order.md): | |
"component-member-order": { | |
"severity": "warn", | |
"options": { | |
"order": [ | |
"lifecycle", | |
"stencil-method", | |
"prop", | |
"watched-prop", | |
"event", | |
"own-prop", | |
"internal-prop", | |
"own-method", | |
"element", | |
"state", | |
"watched-state", | |
"listen", | |
"method" | |
], | |
"alphabetical": true | |
} | |
} | |
*/ | |
import { | |
Component, | |
Element, | |
Event, | |
EventEmitter, | |
Listen, | |
Method, | |
Prop, | |
State, | |
Watch, | |
h | |
} from "@stencil/core"; | |
const CSS = { | |
foo: "foo" | |
}; | |
@Component({ | |
tag: "calcite-boilerplate", | |
styleUrl: "calcite-boilerplate.scss", | |
shadow: true | |
}) | |
export class CalciteBoilerplate { | |
// -------------------------------------------------------------------------- | |
// | |
// Lifecycle | |
// | |
// -------------------------------------------------------------------------- | |
componentWillLoad() { | |
// ... | |
} | |
// -------------------------------------------------------------------------- | |
// | |
// Rendering | |
// | |
// -------------------------------------------------------------------------- | |
render() { | |
return <div class={CSS.foo} />; | |
} | |
// -------------------------------------------------------------------------- | |
// | |
// Properties | |
// | |
// -------------------------------------------------------------------------- | |
@Prop() | |
someProp = true; | |
// -------------------------------------------------------------------------- | |
// | |
// Events | |
// | |
// -------------------------------------------------------------------------- | |
@Event() | |
calciteBoilerplateEvent: EventEmitter; | |
// -------------------------------------------------------------------------- | |
// | |
// Private Properties | |
// | |
// -------------------------------------------------------------------------- | |
internalProp: string; | |
internalMethod(): void { | |
// ... | |
} | |
@Element() | |
el: HTMLElement; | |
@State() | |
internalRenderableProp = 0; | |
// -------------------------------------------------------------------------- | |
// | |
// Private Methods | |
// | |
// -------------------------------------------------------------------------- | |
@Watch("someProp") | |
handleSomeProp(): void { | |
// ... | |
} | |
@Watch("internalRenderableProp") | |
handleInternalSomeProp(): void { | |
// ... | |
} | |
@Listen("someEvent") | |
handleSomeEvent(): void { | |
// ... | |
} | |
// -------------------------------------------------------------------------- | |
// | |
// Public Methods | |
// | |
// -------------------------------------------------------------------------- | |
@Method() | |
publicMethod(): void { | |
// ... | |
} | |
} |
WRT private vars, I'm not sure we need to. StencilJS doesn't expose undecorated properties or methods, so I'm not sure what we get out of prefixing with an underscore or using the private
keyword. Would a component care internally whether a property/method is private?
Would a component care internally whether a property/method is private?
Nope.
👍
Should el
be in private properties? I don't think its public right?
Moved! 💥
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that sounds good. ^