当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.map方法代码示例

本文整理汇总了TypeScript中rx.Observable.map方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.map方法的具体用法?TypeScript Observable.map怎么用?TypeScript Observable.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rx.Observable的用法示例。


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

示例1: ButtonFactory

export function ButtonFactory(sources: any, props$: Observable<ButtonProps>,
    children: Array<CycleComponent>): CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    const element = props.href ? 'a' : 'button';
    const level = props.primary ? 'primary' : props.accent ? 'accent' : 'neutral';
    const shape = props.flat ? 'flat' : props.raised ? 'raised' : props.floating ?
      'floating' : 'flat';

    const className = classNames([style[shape]], {
      [style[level]]: props.neutral,
      [style.mini]: props.mini,
      [style.inverse]: props.inverse
    }, props.className);

    return (
      h(element, { props: { className }, attrs: { 'data-cycle-ui': 'button' } }, [
        //icon ? <FontIcon className={style.icon} value={icon}/> : null,
        //label: props.label
      // ,
        props.label &&
          span(props.label),
        children
      ])
    );
  });

  return {
    DOM: vtree$,
  };
};
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:31,代码来源:Button.ts

示例2: RadioGroupFactory

function RadioGroupFactory(sources: any, props$: Observable<RadioGroupProps>,
                        children: Array<RadioButton>): CycleDomComponent {
  const childrenDOMs: any[] = [];
  const childrenValues: Observable<any>[] = [];
  //TODO: allow other kinds of children?
  for (let childRadio of children) {
    // TODO: maybe remove RadioButton interface if I can make value$ compile using CycleDomComponent
    // interface
    childrenValues.push(childRadio.value$);
    childrenDOMs.push(childRadio.DOM);
  }

  const itemMouseClick$ = Observable.just('RadioFirst');
  const vtree$ = props$.map( (props) => {

    const $radioGroupSelectedValue = Observable.combineLatest(childrenValues, (...values) => {
      return { itemMouseClick$ };
    }).startWith(props.value)
      .do(x => console.log('radioGroupSelectedValue ' + x));

    const className = classNames('radioGroup', props.className);

    return (
      div( { props: { className }, attrs: { 'data-cycle-ui': 'radio-group' } },
        childrenDOMs
      )
    );
  });

  return {
    DOM: vtree$,
  };

}
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:34,代码来源:RadioGroup.ts

示例3: OverlayFactory

export function OverlayFactory(props$: $<OverlayProps>,
    children?: any[]): CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    const className = classNames(style.root, {
      [style.active]: props.active,
      [style.invisible]: props.invisible
    }, props.className);

    return div( { props: { className } }, [
      div( { props: { className: style.overlay } },
        children
      )
    ]);
    // return (
    //   h('dialog', {hook: {insert}, props: { className } }, [
    //    div( { props: { className } }, [
    //   div( { props: { className: style.overlay } },
    //     children
    //   )
    // ]);

  });

  return {
    DOM: vtree$,
  };
}
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:28,代码来源:Overlay.ts

示例4: CardTitleFactory

export function CardTitleFactory(sources: any, props$: Observable<CardTitleProps>,
                       children: string | Array<CycleComponent> | CycleComponent):
                       CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    //TODO: do Avatars at some point

    //let avatarComponent;

    // if (typeof avatar === 'string') {
    //   avatarComponent = <Avatar image={avatar} />;
    // } else {
    //   avatarComponent = avatar;
    // }

    const className = classNames(style.cardTitle, {
      // [style.small]: props.avatar,
      // [style.large]: !props.avatar
    }, props.className);
    const titleDOM = props.title &&
      h5(`.${style.title}`, props.title);

    const childrenAsStringDOM = children && typeof children === 'string' &&
      h5(`.${style.title}`,
        children
      );

    const subtitleDOM = props.subtitle &&
      p(`.${style.subtitle}`, props.subtitle);

    const childrenAsArray = children && typeof children !== 'string' &&
      children;

    return (
      div( { props: { className } }, [
        div(concat([],
          titleDOM,
          childrenAsStringDOM,
          subtitleDOM,
          childrenAsArray
        )),
      ]
      // [
      //   //TODO: Avatars
      //   // {avatarComponent && (
      //   //   <div className={style.avatar}>
      //   //     {avatarComponent}
      //   //   </div>
      //   // )}
      // ]
      )
    );
  });

  return {
    DOM: vtree$,
  };
};
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:58,代码来源:CardTitle.ts

示例5: Drawers

export function Drawers(sources: any) {
  const DOM = sources.DOM;

  const showDrawerClick$ = DOM.select('.showDrawer').events('click').
    map( (ev: Event) => 'show').
    do((x: any) => console.log('show: ' + x));

  const drawerClose$ = sources.DOM.select('dialog').events('close').
    startWith(false).
    map(() => false).
    do((x: any) => console.log('drawerCloseFromApp: ' + x));

  const isDrawerActive$: $<boolean> = $.merge<boolean>(
    showDrawerClick$.map(true)
    , drawerClose$.map(false)
  ).startWith(false);

  function view(isDrawerActive: boolean) {
    const drawer = (
      Drawer(sources, { isolate: false, className: 'drawer', active: isDrawerActive, type: 'left' }, [
        h5('This is a left drawer'),
        p('A drawer can have multiple children controls'),
        Input(sources, { label: 'Input in a Drawer' }).DOM,
      ])
    );

    // (<any>drawer).closeEvent$.subscribe( (x: any) => {
    //   console.log('close obs event: ' + x);
    // });

    return (
      Card(sources, { isolate: false, className: 'demoDrawers' }, [
        CardTitle(sources, { isolate: false, title: 'Drawers (Work in progress)' }, [
          CardText(sources, { isolate: true }, [
            Button(sources, { isolate: false, className: 'showDrawer', label: 'Show Drawer',
              raised: true }).DOM,
            p('is active: ' + isDrawerActive),
            drawer.DOM,
          ]).DOM
        ]).DOM
      ]).DOM
    );
  }

  const vtree$ = (
  //  $.combineLatest(drawerClose$, isDrawerActive$, (drawerClose: boolean, isDrawerActive: boolean) => {
    isDrawerActive$.map( (isDrawerActive: boolean) => {
      return view(isDrawerActive);
    })
  );

  return {
    DOM: vtree$,
  };
}
开发者ID:eldarlabs,项目名称:cycle-ui-typescript-webpack,代码行数:55,代码来源:Drawers.ts

示例6: RadioFactory

function RadioFactory(sources: any, props$: Observable<RadioProps>): CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    const className = classNames(style[props.checked ? 'radio-checked' : 'radio'], props.className);

    return (
      div( { props: { className }, attrs: { 'data-cycle-ui': 'radio' } } )
    );
  });

  return {
    DOM: vtree$,
  };
};
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:14,代码来源:Radio.ts

示例7: DialogFactory

export function DialogFactory(props$: $<DialogProps>,
    children?: CycleComponent[]): CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    const actionsDOM = props.actions.map((action) => {
      //const className = ClassNames(style.button, {[action.className]: action.className});
      if (typeof action.DOM === 'undefined') {
        return action;
      }
      return action.DOM;
    });

    const className = classNames([ style.root, style[props.type] ], {
      [style.active]: props.active
    }, props.className);

    const insert = (vnode: any) => {
      const dialog: any = document.querySelector('dialog');
      dialogPolyfill.registerDialog(dialog);
      if (props.active) {
        dialog.showModal();
      } else {
        const overlay: any = document.querySelector('._dialog_overlay');
        if (overlay != null) {
          console.log('removing dialog overlay');
          overlay.parentNode.removeChild(overlay);
        }
      }
    };

    return (
//      Overlay( { active: props.active }, [
        h('dialog', {hook: {insert}, props: { className }, attrs: { 'data-cycle-ui': 'dialog' } }, [
          section( { props: { className: style.body },
            attrs: { role: 'body' } }, concat([],
            props.title && h6( { props: { className: style.title } }, props.title),
            children
          )),
          nav( { props: { role: 'navigation', className: style.navigation } },
            actionsDOM
          )
        ])
//      ]).DOM
    );
  });

  return {
    DOM: vtree$,
  };
}
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:50,代码来源:Dialog.ts

示例8: Dialogs

export function Dialogs(sources: any) {
  const DOM = sources.DOM;

  const cancelClick$ = DOM.select('.cancel').events('click').
    map( (ev: Event) => 'cancel');
  const saveClick$ = DOM.select('.save').events('click').
    map( (ev: Event) => 'save').
    do((x: any) => console.log('save: ' + x));

  const showDialogClick$ = DOM.select('.showDialog').events('click').
    map( (ev: Event) => 'show').
    do((x: any) => console.log('show: ' + x));

  const isDialogActive$: $<boolean> = $.merge<boolean>(
    cancelClick$.map(false),
    saveClick$.map(false),
    showDialogClick$.map(true)
  ).startWith(false);

  const cancelButton = Button(sources, { className: 'cancel', label: 'Cancel' } );
  const saveButton = Button(sources, { className: 'save', label: 'Save' } );

  function view(isDialogActive: boolean) {
    return (
      DemoCardView(sources, 'Dialogs (Work in progress)', [
        CardText(sources, [
          Button(sources, { className: 'showDialog', label: 'Show Modal Dialog',
            raised: true }).DOM,
          p('is active: ' + isDialogActive),
          Dialog({ title: 'Test Dialog', active: isDialogActive,
            actions: [cancelButton.DOM, saveButton] }, [
              p('This is a dialog'),
              p('A dialog can have multiple children controls')
            ]
          ).DOM
        ]).DOM
      ])
    );
  }

  const vtree$ = (
    isDialogActive$.map( (isDialogActive) => {
      return view(isDialogActive);
    })
  );

  return {
    DOM: vtree$,
  };
}
开发者ID:eldarlabs,项目名称:cycle-ui-typescript-webpack,代码行数:50,代码来源:Dialogs.ts

示例9: CardTextFactory

export function CardTextFactory(sources: any, props$: Observable<CardTextProps>,
                      children: string | Array<CycleComponent>): CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    const className = classNames(style.cardText, props.className);
    console.log(children);
    return (
      div( { props: { className } },
        typeof children === 'string' ? p(children) : children
      )
    );
  });

  return {
    DOM: vtree$,
  };
};
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:17,代码来源:CardText.ts

示例10: CardActionsFactory

export function CardActionsFactory(sources: any, props$: Observable<CardActionsProps>,
                         children: Array<CycleComponent>): CycleDomComponent {
  const vtree$ = props$.map( (props) => {

    const className = classNames(style.cardActions, props.className);

    return (
      div( { props: { className } },
        children
      )
    );
  });

  return {
    DOM: vtree$,
  };
};
开发者ID:eldarlabs,项目名称:cycle-ui,代码行数:17,代码来源:CardActions.ts


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