當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。