• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript xstream.combine函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中xstream.combine函数的典型用法代码示例。如果您正苦于以下问题:TypeScript combine函数的具体用法?TypeScript combine怎么用?TypeScript combine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了combine函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: BmiCalculator

function BmiCalculator(sources: Sources): Sinks {
  let WeightSlider = isolate(LabeledSlider);
  let HeightSlider = isolate(LabeledSlider);

  let weightProps$ = xs.of<LabeledSliderProps>({
    label: 'Weight', unit: 'kg', min: 40, initial: 70, max: 140
  }).remember();
  let heightProps$ = xs.of<LabeledSliderProps>({
    label: 'Height', unit: 'cm', min: 140, initial: 170, max: 210
  }).remember();

  let weightSlider = WeightSlider({DOM: sources.DOM, props$: weightProps$});
  let heightSlider = HeightSlider({DOM: sources.DOM, props$: heightProps$});

  let bmi$ = xs.combine(weightSlider.value$, heightSlider.value$)
    .map(([weight, height]) => {
      let heightMeters = height * 0.01;
      let bmi = Math.round(weight / (heightMeters * heightMeters));
      return bmi;
    }).remember();

  return {
    DOM: xs.combine(bmi$, weightSlider.DOM, heightSlider.DOM)
      .map(([bmi, weightVTree, heightVTree]) =>
        div([
          weightVTree,
          heightVTree,
          h2('BMI is ' + bmi)
        ])
      )
  };
}
开发者ID:DrUNE,项目名称:cyclejs,代码行数:32,代码来源:BmiCalculator.ts


示例2: BmiCalculator

function BmiCalculator(sources: Sources): Sinks {
  const WeightSlider = isolate(LabeledSlider) as typeof LabeledSlider;
  const HeightSlider = isolate(LabeledSlider) as typeof LabeledSlider;

  const weightProps$ = xs.of({
    label: 'Weight', unit: 'kg', min: 40, initial: 70, max: 140,
  }).remember();
  const heightProps$ = xs.of({
    label: 'Height', unit: 'cm', min: 140, initial: 170, max: 210,
  }).remember();

  const weightSlider = WeightSlider({DOM: sources.DOM, props$: weightProps$});
  const heightSlider = HeightSlider({DOM: sources.DOM, props$: heightProps$});

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

  const vdom$ = xs.combine(bmi$, weightSlider.DOM, heightSlider.DOM)
    .map(([bmi, weightVTree, heightVTree]) =>
      div([
        weightVTree,
        heightVTree,
        h2('BMI is ' + bmi),
      ]),
    );

  return {
    DOM: vdom$,
  };
}
开发者ID:joeldentici,项目名称:cyclejs,代码行数:34,代码来源:BmiCalculator.ts


示例3: getGameHighScores

  let main = ({ bot }: Sources) => ({
    bot: xs.from([
      xs.of(sendGame(
        { chat_id: GROUP_ID,
          game_short_name: 'test' },
        {})),

      xs.combine(
        bot.events('message')
          .map<TcombUser>(x => x.message.from)
          .debug(() => bot.dispose()),
        bot.responses.take(1))
        .map(([user, message]) => ({ message, user }))
        .map(({ message, user }) =>
          getGameHighScores(
            { user_id: user.id, message_id: message.message_id },
            { message })),

      xs.combine(
        xs.combine(
          bot.responses
            .take(1),
          bot.events('message')
            .debug(() => bot.dispose())
            .map(x => x.message.from)),
        bot.responses
          .drop(1)
          .filter(Array.isArray)
          .map(xs.from)
          .flatten())
        .map(([[message, user], score]) => ({ message, user, score }))
        .filter(({user, score}) => user.id === score.user.id)
        .map(({ score: { score }, user, message }) =>
          setGameScore(
            { score: score + 1, user_id: user.id, message_id: message.message_id },
            { message })),

      bot.responses
        .drop(1)
        .filter(prop('game'))
        .map(x => x.game)
        .debug((game: TcombGame) => {
          bot.dispose()
          t.ok(Game.is(Game(game)), 'game satisfies typecheck')
          t.end()
        })
    ])
  })
开发者ID:goodmind,项目名称:cycle-telegram,代码行数:48,代码来源:xstream.ts


示例4: GraphSerializer

function GraphSerializer(
  sources: GraphSerializerSources,
): GraphSerializerSinks {
  const zapSpeed$ = sources.Settings
    .map(settings =>
      (sources.FromPanel as Stream<ZapSpeed>).startWith(settings.zapSpeed),
    )
    .flatten();

  const graph$ = sources.DebugSinks.filter(sinksAreXStream).map(buildGraph);

  const serializedGraph$ = xs
    .combine(graph$, zapSpeed$)
    .map(setupZapping)
    .compose(makeObjectifyGraph(sources.id))
    .map(object => CircularJSON.stringify(object));

  const invalid$ = sources.DebugSinks
    .filter(x => !sinksAreXStream(x))
    .mapTo('');

  return {
    graph: xs.merge(serializedGraph$, invalid$),
  };
}
开发者ID:cyclejs,项目名称:cyclejs,代码行数:25,代码来源:graphSerializer.ts


示例5: Counter

function Counter(sources: Sources): Sinks {
	const IncrementButton = isolate(Button);
	const DecrementButton = isolate(Button);

	let incrementButtonProps$ = xs.of<ButtonProps>({
    text: 'Increment', amount: 1
  }).remember();
	let decrementButtonProps$ = xs.of<ButtonProps>({
    text: 'Decrement', amount: -1
  }).remember();

	let incrementButton = IncrementButton({DOM: sources.DOM, props$: incrementButtonProps$});
	let decrementButton = DecrementButton({DOM: sources.DOM, props$: decrementButtonProps$});

	let count$ = xs.merge(incrementButton.delta$, decrementButton.delta$)
		.fold((acc, x) => acc + x, 0);

	return {
		DOM: xs.combine(count$, incrementButton.DOM, decrementButton.DOM)
      .map(([count, incrementVTree, decrementVTree]) =>
        div([
          incrementVTree,
					decrementVTree,
					h2('Clicks: ' + count),
        ])
      )
	};
}
开发者ID:mxstbr,项目名称:cyclejs-counter,代码行数:28,代码来源:Counter.ts


示例6: app

    function app(sources: {DOM: MainDOMSource}) {
      const foo$ = sources.DOM.isolateSink(xs.of(
        div('.container', [
          h4('.header', 'Correct'),
        ]),
      ), '#foo');

      const bar$ = sources.DOM.isolateSink(xs.of(
        div('.container', [
          h3('.header', 'Wrong'),
        ]),
      ), '#bar');

      const vdom$ = xs.combine(foo$, bar$).map(([foo, bar]) =>
        div('.top-most', [
          foo,
          bar,
          h2('.header', 'Correct'),
        ]),
      );

      return {
        DOM: vdom$,
      };
    }
开发者ID:whitecolor,项目名称:cyclejs,代码行数:25,代码来源:isolation.ts


示例7: model

function model(users$: Stream<User[]>, homeworlds$: Stream<Planet[]>): Stream<ViewState[]> {
  return xs.combine(users$, homeworlds$)
    .map(([users, homeworlds]) => {
      return users.map(user => {
        const homeworld = homeworlds.filter(hw => hw.url === user.homeworld)[0]
        return { user, homeworld }
      })
    })
}
开发者ID:jaketrent,项目名称:swapi-cycle-ts,代码行数:9,代码来源:index.ts


示例8:

 .map(actorId =>
   xs
     .combine(simulationMousePosition$, playing$, recording$)
     .map(([position, playing, recording]) => ({
       actorId,
       position,
       playing,
       recording
     }))
     .endWhen(mouseUp$)
开发者ID:helix-pi,项目名称:helix-pi,代码行数:10,代码来源:editor.ts


示例9: main

 function main(sources: {DOM: MainDOMSource}) {
   const child = isolate(Child, 'child')(sources);
   // change parent key, causing it to be recreated
   const x$ = xs.periodic(120).map(x => x + 1).startWith(0).take(4);
   const innerDOM$ = xs.combine(x$, child.DOM)
     .map(([x, childVDOM]) =>
       div(`.parent${x}`, {key: `key${x}`}, [childVDOM, `${x}`]),
     );
   return {
     DOM: innerDOM$,
   };
 }
开发者ID:whitecolor,项目名称:cyclejs,代码行数:12,代码来源:isolation.ts


示例10: Client

function Client (sources) {
  const stateUpdate$ = sources.Socket.messages
    .filter(message => message.type === 'UPDATE_STATE')
    .map(message => message.data);

  const stateOverride$ = stateUpdate$
    .map(serverState => ({type: 'OVERRIDE', data: serverState}));

  const id$ = sources.Socket.messages
    .filter(message => message.type === 'SET_ID')
    .map(message => message.data)
    .remember();

  const move$ = sources.DOM
    .select('svg')
    .events('click')
    .map(mousePosition)
    .map(destination => ({type: 'MOVE', data: destination}));

  const attack$ = sources.DOM
    .select('.enemy')
    .events('click')
    .debug(event => event.stopPropagation())
    .map(event => ({type: 'ATTACK', data: event.target.id}));

  const chat$ = sources.DOM
    .select('document')
    .events('keydown')
    .map(event => ({type: 'CHAT', data: event.key}));

  const action$ = xs.merge(
    move$,
    chat$,
    attack$
  );

  const gameActionWithId$ = id$
    .map(id => action$.map(action => ({...action, id})))
    .flatten();

  const gameAction$ = xs.merge(gameActionWithId$, stateOverride$);

  const state$ = Game({
    Animation: sources.Animation,
    action$: gameAction$ as Stream<Action>
  });

  return {
    DOM: xs.combine(id$, state$).map(view),
    Socket: action$
  }
}
开发者ID:Widdershin,项目名称:schism,代码行数:52,代码来源:client.ts



注:本文中的xstream.combine函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript xstream.create函数代码示例发布时间:2022-05-25
下一篇:
TypeScript xss.FilterXSS类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap