4
私はrxjsを学んでいます。ドロップダウンコンポーネントのデコレータ "トグル可能"を作成します。すべて正常に動作しますが、私はそれが気に入らないのです。どうすれば "トグル/非表示"状態を削除できますか?Rxjsでトグルする方法
rxjs、react.js、recomposeを使用します。 Dropdownコンポーネントのためのtoogleableデコレータです。
const show$ = Observable.merge(
toggle$.mapTo(prev => !prev),
hide$.mapTo(prev => false))
.startWith(false)
.scan((state, changeState) => changeState(state));
別:あなたは以前の状態の関数に$を非表示/トグル$をマッピングすることにより、条件のないショーの$を実装することができますドロップダウンボタンのそれのデコレータ
// hideHandler caller
class Foo extends Component {
constructor(props) {
super(props);
this.refButton.bind(this);
this.documentClick$ = Observable.fromEvent(global.document, 'click')
.filter(event => this.button !== event.target)
.do((event) => { this.props.onHide(event); });
}
componentDidMount() {
this.documentClick$.subscribe();
}
componentWillUnmount() {
this.documentClick$.unsubscribe();
}
refButton = (ref) => {
this.button = ref;
}
}