CycleJS - 订阅子组件的点击事件

CycleJS - subscribing click events of a child component

我是 CycleJS 的新手,我想从父组件订阅子组件的 'click' 事件;但是,它不起作用。我能够订阅子组件内的事件。是否可以从其父组件订阅子组件的事件?如果可能的话,我该怎么做?这是父组件:

import Rx from 'rx';
import Cycle from '@cycle/core';
import CycleDOM from '@cycle/dom';
import isolate from '@cycle/isolate';
import _ from 'underscore';
import Inboxmails from './../components/inboxmails';

const {div} = CycleDOM;    
const Main =  (sources) => {

        const inboxmails=Inboxmails({DOM: sources.DOM});

        sources.DOM.select('#inbox_1')
                .events('click')
                .do(event => event.preventDefault())
                .subscribe(event => {
                    console.log(event);
                });


        const vtree$ = Rx.Observable.of(
                    div('.wrapper', [
                            inboxmails.DOM
                        ]));

            return {
                DOM: vtree$
            };
        };



    export default (sources) => isolate(Main)(sources);

这是子组件

import Rx from 'rx';
import Cycle from '@cycle/core';
import CycleDOM from '@cycle/dom';
import isolate from '@cycle/isolate';
const { div} = CycleDOM;

const Inboxmails = function (sources) {
    const inboxmails$ = Rx.Observable.of(div([
        div("#inbox_1",[
            "Click here"
        ])])
    );
    return {
        DOM: inboxmails$    
    };
};

export default (sources) => isolate(Inboxmails)(sources);

让 child return 收集 parent 需要的事件。

const Inboxmails = function (sources) {
    const inboxmails$ = Rx.Observable.of(div([
        div("#inbox_1",[
            "Click here"
        ])])
    );
    return {
        DOM: inboxmails$,
        clicks: sources.DOM.select('#inbox_1').events('click')  
    };
};

那么parent可以用inboxmails.clicks.

但是,在 Cycle.js 中,您的代码中不应该有任何订阅(除非是为了调试)。订阅呼叫应该只在驱动程序中。