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

TypeScript isolate.default函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: main

 function main(sources: {DOM: MainDOMSource}) {
   const first = isolate(Child, 'first')(sources);
   const second = isolate(Child, 'second')(sources);
   const oneChild = [first];
   const twoChildren = [first, second];
   const vnode$ = xs.periodic(50).take(1).startWith(-1)
     .map(i => i === -1 ? oneChild : twoChildren)
     .map(children =>
       xs.combine(...children.map(child => child.DOM))
         .map(childVNodes => div('.parent', childVNodes)),
     ).flatten();
   return {
     DOM: vnode$,
   };
 }
开发者ID:whitecolor,项目名称:cyclejs,代码行数:15,代码来源:isolation.ts


示例5: Array

 (acc: InternalInstances<Si>, nextState: Array<any> | any) => {
   const dict = acc.dict;
   if (Array.isArray(nextState)) {
     const nextInstArray = Array(nextState.length) as Array<
       Si & {_key: string}
     >;
     const nextKeys = new Set<string>();
     // add
     for (let i = 0, n = nextState.length; i < n; ++i) {
       const key = `${itemKey ? itemKey(nextState[i], i) : i}`;
       nextKeys.add(key);
       if (!dict.has(key)) {
         const stateScope = itemKey ? instanceLens(itemKey, key) : `${i}`;
         const otherScopes = itemScope(key);
         const scopes =
           typeof otherScopes === 'string'
             ? {'*': otherScopes, [name]: stateScope}
             : {...otherScopes, [name]: stateScope};
         const sinks: any = isolate(itemComp, scopes)(sources);
         dict.set(key, sinks);
         nextInstArray[i] = sinks;
       } else {
         nextInstArray[i] = dict.get(key) as any;
       }
       nextInstArray[i]._key = key;
     }
     // remove
     dict.forEach((_, key) => {
       if (!nextKeys.has(key)) {
         dict.delete(key);
       }
     });
     nextKeys.clear();
     return {dict: dict, arr: nextInstArray};
   } else {
     dict.clear();
     const key = `${itemKey ? itemKey(nextState, 0) : 'this'}`;
     const stateScope = identityLens;
     const otherScopes = itemScope(key);
     const scopes =
       typeof otherScopes === 'string'
         ? {'*': otherScopes, [name]: stateScope}
         : {...otherScopes, [name]: stateScope};
     const sinks: any = isolate(itemComp, scopes)(sources);
     dict.set(key, sinks);
     return {dict: dict, arr: [sinks]};
   }
 },
开发者ID:,项目名称:,代码行数:48,代码来源:


示例6: main

    function main(sources: {state: StateSource<any>}) {
      assert(sources.state);
      assert(sources.state.stream);
      const expected = [[3, 5, 6], [3, 15, 6], [3, 6]];
      sources.state.stream.addListener({
        next(x) {
          assert.deepEqual(x, expected.shift());
          calledMain += 1;
        },
        error(e) {
          done(e);
        },
        complete() {},
      });

      const childSinks = isolate(secondEntry, 1)(sources);
      assert(childSinks.state);
      const childReducer$ = childSinks.state;

      const parentReducer$ = xs.of(function initReducer(prevState: any): any {
        return [3, 5, 6];
      });
      const reducer$ = xs.merge(parentReducer$, childReducer$) as Stream<
        Reducer<any>
      >;

      return {
        state: reducer$,
      };
    }
开发者ID:,项目名称:,代码行数:30,代码来源:


示例7: Main

    function Main(sources: {state: StateSource<any>}) {
      sources.state.stream.addListener({
        next(x) {
          assert.deepEqual(x.list, expected.shift());
        },
        error(e) {
          done(e.message);
        },
        complete() {
          done('complete should not be called');
        },
      });

      const childSinks = isolate(List, 'list')(sources);
      const childReducer$ = childSinks.state;

      const initReducer$ = xs.of(function initReducer(prevState: any): any {
        return {list: [{val: 3}]};
      });

      const addReducer$ = xs
        .of(function addSecond(prev: any) {
          return {list: prev.list.concat({val: null})};
        })
        .compose(delay(100));

      const parentReducer$ = xs.merge(initReducer$, addReducer$);
      const reducer$ = xs.merge(parentReducer$, childReducer$) as Stream<
        Reducer<any>
      >;

      return {
        state: reducer$,
      };
    }
开发者ID:,项目名称:,代码行数:35,代码来源:


示例8: main

function main(sources: Sources): Sinks {
  const stateUpdate$ = sources.websocket.get('state-update')
    .map(msg => msg.data as BootstrapMessage)
  const board = isolate(Board)(sources, stateUpdate$)

  const boardWebsocket$ = Stream.merge(
    board.moveNote$.map(noteEvent => ({
      type: 'move-note',
      data: noteEvent,
    })),
    board.addNote$.mapTo({ type: 'add-note' }),
    board.editNote$.map(({ id, label }) => ({
      type: 'change-note-label',
      data: { id, label }
    })),
    board.noteDelete$.map(id => ({
      type: 'delete-note',
      data: { id }
    }))
  )

  return {
    DOM: board.DOM,
    websocket: Stream.merge(boardWebsocket$, Stream.of({ type: 'init' }))
      .debug('websocket$'),
    preventDefault: board.preventDefault,
    focus: board.focus,
  }
}
开发者ID:JamesHageman,项目名称:xstream-scrumbler,代码行数:29,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript most-run.default函数代码示例发布时间:2022-05-28
下一篇:
TypeScript http.makeHTTPDriver函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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