在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡(luò)安全/ cycle組件化中的demo,為什么移動(dòng)range時(shí)候沒效果?

cycle組件化中的demo,為什么移動(dòng)range時(shí)候沒效果?

import xs from 'xstream';
import {run} from '@cycle/run';
import {div, input, p, makeDOMDriver} from '@cycle/dom';
import {html} from 'snabbdom-jsx';


function main(sources) {
    const weightProps$ = xs.of({
        label: 'Weight', unit: 'kg', min: 40, value: 70, max: 150
    })

    const heightProps$ = xs.of({
        label: 'Height', unit: 'cm', min: 10, value: 170, max: 210
    })

    const weightSources = {
        DOM: sources.DOM,
        props: weightProps$
    }

    const heightSources = {
        DOM: sources.DOM,
        props: heightProps$
    }

    const weightSlider = LabeledSlider(weightSources)
    const heightSlider = LabeledSlider(heightSources)
    const weightDom$ = weightSlider.DOM
    const weightValue$ = weightSlider.value
    const heightVDom$ = heightSlider.DOM
    const heightValue$ = heightSlider.value

    const value$ = xs.combine(weightValue$, heightValue$)
    .map( ([weight, height]) => {
        const heightMeters = height * 0.01
        const bmi = Math.round(weight / (heightMeters * heightMeters))
        return bmi
    })

    const dom$ = xs.combine(value$, weightDom$, heightVDom$)
    .map( ([bmi, weight, height]) => {
        return  <div>
                    { weight }
                    { height }
                    <h2>{ 'BMI is ' + bmi }</h2>
                </div>
    })
  return {
      DOM: dom$
  }
}


function LabeledSlider(sources) {
    const domSources = sources.DOM
    const props$ = sources.props

    const newValue$ = domSources
    .select('.slider')
    .events('input')
    .map(ev => ev.target.value)

    const state$ = props$
    .map(
        props => newValue$.map(val => ({
            label: props.label,
            unit: props.unit,
            min: props.min,
            value: val,
            max: props.max
          })).startWith(props)
    )
    .flatten()
    .remember()


    const vdom$ = state$.map( state => {
        return  <div class="labeled-slider">
                    <span class="label">{state.label + ' ' + state.value + state.unit}</span>
                    <input type="range" class="slider" min={state.min} max={state.max} value={state.value}/>
                </div> 
    })
    const sinks = {
        DOM: vdom$,
        value: state$.map(val => val.value),
    }
    return sinks
}

const drivers = {
  DOM: makeDOMDriver('#app')
};

run(main, drivers);

clipboard.png

回答
編輯回答
祉小皓

class => className
cycle和 react是一樣的
而 vue則使用 class

2017年8月20日 21:07