Files
atom/packages/about/lib/etch-component.js
2019-05-31 18:33:56 +02:00

57 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const etch = require('etch');
/*
Public: Abstract class for handling the initialization
boilerplate of an Etch component.
*/
module.exports = class EtchComponent {
constructor(props) {
this.props = props;
etch.initialize(this);
EtchComponent.setScheduler(atom.views);
}
/*
Public: Gets the scheduler Etch uses for coordinating DOM updates.
Returns a {Scheduler}
*/
static getScheduler() {
return etch.getScheduler();
}
/*
Public: Sets the scheduler Etch uses for coordinating DOM updates.
* `scheduler` {Scheduler}
*/
static setScheduler(scheduler) {
etch.setScheduler(scheduler);
}
/*
Public: Updates the component's properties and re-renders it. Only the
properties you specify in this object will update any other properties
the component stores will be unaffected.
* `props` an {Object} representing the properties you want to update
*/
update(props) {
let oldProps = this.props;
this.props = Object.assign({}, oldProps, props);
return etch.update(this);
}
/*
Public: Destroys the component, removing it from the DOM.
*/
destroy() {
etch.destroy(this);
}
render() {
throw new Error('Etch components must implement a `render` method');
}
};