2016-08-18 47 views
0

我正在努力嘗試將流合併爲一個流,並在h1中顯示文本。爲什麼我無法在cyclejs中使用xstream合併流?

但是不能夠使它發揮作用:

這是我的代碼:

function main(sources) { 
    // single streams 
    let letter$ = xs.of({text: 'abcd'}); 
    let number$ = xs.of({text: '123456'}); 

    //try to combine them into one 
    const combined$ = 
    xs.combine(letter$, number$). 
     map(([ letter, number ]) => { 
     return { text: letter.text + ' ' + number.text }; 
     }); 

    //updates the virtual dom with the reponse 
    const vdom$ = combined$ 
    .map(o => o.text) 
    .startWith('Loading...') 
    .map(text => 
     div('.container', [ 
     h1(text) 
     ]) 
    ); 


    return { 
    DOM: vdom$ 
    }; 
} 

它顯示錯誤說:

index.js:6 TypeError: f is not a function 
at invoke (core.js:36) 
at CombineListener._n (core.js:72) 
at Stream._n (core.js:886) 
at FromArrayProducer._start (core.js:142) 
at Stream._add (core.js:959) 
at CombineProducer._start (core.js:118) 
at Stream._add (core.js:959) 
at MapOperator._start (core.js:681) 
at Stream._add (core.js:959) 
at StartWithOperator._start (core.js:786) 

正在試圖理解爲什麼,但沒有運氣遠。

+0

文件* index.js *中的第6行是什麼? – bloodyKnuckles

+0

'combine'部分在這裏工作正常:http://www.webpackbin.com/VkmIaiCtZ – bloodyKnuckles

+0

謝謝你看看,它看起來像組合流到vtree時發生的問題。 webpackbin是一個很好的建議,這裏是附加代碼: [http://www.webpackbin.com/VkpnY30K-](http://www.webpackbin.com/VkpnY30K-) – ismapro

回答

2

我的問題是使用CycleJS回購中示例的package.json中指定的依賴關係。

這些依賴過時:

https://github.com/cyclejs/cyclejs/blob/master/examples/http-search-github/package.json

"dependencies": { 
    "@cycle/xstream-run": "1.1.0", 
    "@cycle/dom": "10.0.0-rc20", 
    "@cycle/http": "9.0.0-rc3", 
    "xstream": "2.4.x" 
} 

,並依賴於日期爲:拇指檢查最新的穩定依賴

"@cycle/dom": "^12.1.0", 
"@cycle/http": "^10.1.0", 
"@cycle/xstream-run": "^3.0.4", 
"xstream": "^5.3.6" 

規則。

感謝@bloodyKnuckles,以及CycleJS gitter中的所有人。

相關問題