Skip to content

Instantly share code, notes, and snippets.

@jcfranco
Last active June 14, 2019 19:16
Show Gist options
  • Save jcfranco/99f37b2c084700d96662b7809ddd5788 to your computer and use it in GitHub Desktop.
Save jcfranco/99f37b2c084700d96662b7809ddd5788 to your computer and use it in GitHub Desktop.
Boilerplate draft for calcite-app-components
/*
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 {
// ...
}
}
@driskull
Copy link

Should Render be in lifecycle?

@driskull
Copy link

Looks good to me! so we're going with no private or underscore for private vars?

@jcfranco
Copy link
Author

We could if we move stencil-method below lifecycle in the rule. This would move render and hostData to the lifecycle section.

@driskull
Copy link

I think that sounds good. ^

@jcfranco
Copy link
Author

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?

@driskull
Copy link

Would a component care internally whether a property/method is private?

Nope.

👍

@driskull
Copy link

Should el be in private properties? I don't think its public right?

@jcfranco
Copy link
Author

Moved! 💥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment