OPS-2135 Setting a blank background state on unmount

This commit is contained in:
edolyne 2016-08-31 14:58:39 -04:00 committed by Norbert de Langen
parent f84c9c6df6
commit 673837d628
2 changed files with 9 additions and 3 deletions

View File

@ -23,11 +23,13 @@ export default class BackgroundPanel extends React.Component<BackgroundPanelProp
constructor(props) {
super(props);
this.props.channel.on("background-set", backgrounds => this.setState({ backgrounds }));
this.props.channel.on("background-unset", backgrounds => this.setState({ backgrounds: [] }));
}
render () {
const { channel } = this.props;
const backgrounds: BackgroundDetail[] = this.state.backgrounds;
const backgrounds: BackgroundDetail[] = [...this.state.backgrounds];
if (!backgrounds.length) {
return (

View File

@ -1,5 +1,5 @@
import * as React from "react";
import addon from "@kadira/storybook-addons";
import addons from "@kadira/storybook-addons";
const style = {
wrapper: {
@ -25,12 +25,16 @@ export class BackgroundDecorator extends React.Component<any, any> {
constructor(props) {
super(props);
this.channel = addon.getChannel();
this.channel = addons.getChannel();
this.story = this.props.story();
this.channel.on("background", background => this.setState({ background }));
}
componentWillUnmount() {
this.channel.emit("background-unset");
}
componentWillMount() {
this.channel.emit("background-set", this.props.backgrounds);
}