1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-24 12:49:19 +00:00

Organize JS better (#343)

This commit is contained in:
Paulus Schoutsen
2017-07-16 23:31:19 -07:00
committed by GitHub
parent 35c4e1d5ae
commit 2453d6f397
16 changed files with 5 additions and 6 deletions

View File

@@ -0,0 +1,50 @@
import { h, Component } from 'preact';
import TriggerRow from './trigger_row';
export default class Trigger extends Component {
constructor() {
super();
this.addTrigger = this.addTrigger.bind(this);
this.triggerChanged = this.triggerChanged.bind(this);
}
addTrigger() {
const trigger = this.props.trigger.concat({
platform: 'event',
});
this.props.onChange(trigger);
}
triggerChanged(index, newValue) {
const trigger = this.props.trigger.concat();
if (newValue === null) {
trigger.splice(index, 1);
} else {
trigger[index] = newValue;
}
this.props.onChange(trigger);
}
render({ trigger }) {
return (
<div class="triggers">
{trigger.map((trg, idx) => (
<TriggerRow
index={idx}
trigger={trg}
onChange={this.triggerChanged}
/>))}
<paper-card>
<div class='card-actions add-card'>
<paper-button onTap={this.addTrigger}>Add trigger</paper-button>
</div>
</paper-card>
</div>
);
}
}