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


TypeScript Stream.create方法代码示例

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


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

示例1: fromEvent

export function fromEvent(
  element: Element | Document,
  eventName: string,
  useCapture = false,
  preventDefault: PreventDefaultOpt = false,
  passive = false,
): Stream<Event> {
  return Stream.create<Event>({
    element: element,
    next: null,
    start: function start(listener: Listener<Event>) {
      if (preventDefault) {
        this.next = function next(event: Event) {
          preventDefaultConditional(event, preventDefault);
          listener.next(event);
        };
      } else {
        this.next = function next(event: Event) {
          listener.next(event);
        };
      }
      this.element.addEventListener(eventName, this.next, {
        capture: useCapture,
        passive,
      });
    },
    stop: function stop() {
      this.element.removeEventListener(eventName, this.next, useCapture);
    },
  } as Producer<Event>);
}
开发者ID:ntilwalli,项目名称:cyclejs,代码行数:31,代码来源:fromEvent.ts

示例2: start

export default function createEventHandler<T>() {
  interface HandlerProducer<T> extends Producer<T> {
    sendValue: (T) => void,
    _listener: Listener<T>
  }
  
  const producer: HandlerProducer<T> = {
    start(listener) {
      this._listener = listener
    },
    stop() {
      this._listener = null
    },
    sendValue(val: T) {
      if (this._listener) {
        this._listener.next(val)
      }
    },
    _listener: null as Listener<T>
  }
  
  const stream = Stream.create(producer)
  
  return {
    stream,
    handler: (val: T) => {
      producer.sendValue(val)
    }
  }
}
开发者ID:JamesHageman,项目名称:xstream-scrumbler,代码行数:30,代码来源:create-event-handler.ts

示例3: fromEvent

export function fromEvent(
  element: Element | Document,
  eventName: string,
  useCapture = false,
  preventDefault: PreventDefaultOpt = false,
  passive = false
): Stream<Event> {
  let next: ((e: Event) => void) | null = null;
  return Stream.create<Event>({
    start: function start(listener: Listener<Event>) {
      if (preventDefault) {
        next = function _next(event: Event) {
          preventDefaultConditional(event, preventDefault);
          listener.next(event);
        };
      } else {
        next = function _next(event: Event) {
          listener.next(event);
        };
      }
      element.addEventListener(eventName, next, {
        capture: useCapture,
        passive,
      });
    },
    stop: function stop() {
      element.removeEventListener(eventName, next as any, useCapture);
      next = null;
    },
  } as Producer<Event>);
}
开发者ID:cyclejs,项目名称:cyclejs,代码行数:31,代码来源:fromEvent.ts

示例4: fromEvent

export function fromEvent(element: Element | Document,
                          eventName: string,
                          useCapture = false): Stream<Event> {
  return Stream.create<Event>({
    element: element,
    next: null,
    start: function start(listener: Listener<Event>) {
      this.next = function next(event: Event) { listener.next(event); };
      this.element.addEventListener(eventName, this.next, useCapture);
    },
    stop: function stop() {
      this.element.removeEventListener(eventName, this.next, useCapture);
    },
  } as Producer<Event>);
}
开发者ID:whitecolor,项目名称:cyclejs,代码行数:15,代码来源:fromEvent.ts

示例5: complete

export const withCompletionMarble$ = (some$: Stream<Marble>, completion_time?: number): Stream<Marble> => {
  const return$ = Stream.create<Marble>();
  let lastTime = 0;
  const getCompletionTime = () => completion_time == undefined ? lastTime : completion_time;
  setTimeout(() =>
    some$.addListener({
      next: marble => {
        lastTime = marble.time;
        if (!marble.complete) return$.shamefullySendNext(marble);
        else complete(return$, getCompletionTime());
      },
      complete: () => complete(return$, getCompletionTime()),
      error: err => return$.shamefullySendError(err)
    }), 30);
  return return$;
};
开发者ID:artfuldev,项目名称:xstream-marbles,代码行数:16,代码来源:helpers.ts

示例6: start

const getMessageStream = (type: string, socket: SocketIOClient.Socket)
  : Stream<IncomingMessage> => {
    
  const producer : Producer<IncomingMessage> = {
    start(listener) {
      socket.on(type, (data) => {
        listener.next({
          type,
          data
        } as IncomingMessage)
      })
    },
    stop() {
      
    }
  }
  return Stream.create(producer)
}
开发者ID:JamesHageman,项目名称:xstream-scrumbler,代码行数:18,代码来源:websocket.ts


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