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


TypeScript Stream.map方法代码示例

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


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

示例1: Button

function Button(sources: Sources): Sinks {
	let props$: Stream<ButtonProps> = sources.props$;
	const click$ = sources.DOM.select('.button').events('click')
	const delta$ = props$.map(
		(props) => click$.map((ev) => props.amount)
	).flatten();
	const vdom$ = props$.map(props => button('.button', [props.text]));

	return {
		DOM: vdom$,
		delta$: delta$
	}
}
开发者ID:mxstbr,项目名称:cyclejs-counter,代码行数:13,代码来源:Button.ts

示例2: __commits

 private __commits() {
   const response$$: Stream<Stream<Response>> = this.http.select('commits');
   return response$$
     .map(response$ => response$.replaceError(() => xs.of({ status: 500, body: [] } as Response)))
     .flatten()
     .map(response => response.body as Commit[]);
 }
开发者ID:cyclejs-community,项目名称:typescript-starter-cycle,代码行数:7,代码来源:github.ts

示例3: totalIsolateSink

export function totalIsolateSink(
  sink: Stream<VNode | null | undefined>,
  fullScope: string,
): Stream<VNode | null | undefined> {
  return sink.map(node => {
    if (!node) {
      return node;
    }
    // Ignore if already had up-to-date full scope in vnode.data.isolate
    if (node.data && (node.data as any).isolate) {
      const isolateData = (node.data as any).isolate as string;
      const prevFullScopeNum = isolateData.replace(/(cycle|\-)/g, '');
      const fullScopeNum = fullScope.replace(/(cycle|\-)/g, '');

      if (
        isNaN(parseInt(prevFullScopeNum)) ||
        isNaN(parseInt(fullScopeNum)) ||
        prevFullScopeNum > fullScopeNum
      ) {
        // > is lexicographic string comparison
        return node;
      }
    }

    // Insert up-to-date full scope in vnode.data.isolate, and also a key if needed
    node.data = node.data || {};
    (node.data as any).isolate = fullScope;
    if (typeof node.key === 'undefined') {
      node.key = SCOPE_PREFIX + fullScope;
    }
    return node;
  });
}
开发者ID:joeldentici,项目名称:cyclejs,代码行数:33,代码来源:isolate.ts

示例4: driver

 function driver(sink: Stream<number>): Stream<string> {
   return sink.map(x => 'a' + 10).debug(x => {
     assert.strictEqual(x, 'a10');
     assert.strictEqual(mutable, 'correct');
     spy();
   });
 }
开发者ID:joeldentici,项目名称:cyclejs,代码行数:7,代码来源:index.ts

示例5: intent

function intent(HTTPSource: HTTPSource): Intent {
  const url = 'http://swapi.co/api/people/'

  const usersReq$: Stream<RequestOptions> = xs.of({ url, category: 'users' })

  const users$: Stream<User[]> = HTTPSource
    .select('users')
    .flatten()
    .map((res: Response<UsersResBody>) => res.body.results)

  const homeworldsReq$: Stream<RequestOptions> = users$.map((users: User[]): Stream<RequestOptions> => {
    return xs.fromArray(users.map((user: User): RequestOptions => {
      return { url: user.homeworld, category: 'homeworld' }
    }))
  }).flatten()

  const homeworlds$ = HTTPSource
    .select('homeworld')
    .compose(flattenConcurrently)
    .map((res: Response<Planet>) => res.body)
    .fold((acc: Planet[], homeworld: Planet) => {
      acc = acc.concat(homeworld)
      return acc
    }, [])

  return { users$, homeworlds$, usersReq$, homeworldsReq$ }
}
开发者ID:jaketrent,项目名称:swapi-cycle-ts,代码行数:27,代码来源:index.ts

示例6: httpDriver

 function httpDriver(request$: Stream<RequestInput>, name: string): HTTPSource {
   const response$$ = request$
     .map(requestInputToResponse$);
   const httpSource = new MainHTTPSource(response$$, name, []);
   response$$.addListener({next: () => {}, error: () => {}, complete: () => {}});
   return httpSource;
 }
开发者ID:whitecolor,项目名称:cyclejs,代码行数:7,代码来源:http-driver.ts

示例7: __commitBySha

 private __commitBySha(sha: string) {
   const response$$: Stream<Stream<Response>> = this.http.select(`commit-by-sha-${sha}`);
   return response$$
     .map(response$ => response$.replaceError(() => xs.of({ status: 500, body: {} } as Response)))
     .flatten()
     .map(response => response.body as Commit);
 }
开发者ID:cyclejs-community,项目名称:typescript-starter-cycle,代码行数:7,代码来源:github.ts

示例8: htmlDriver

 function htmlDriver(vnode$: Stream<VNode>, name: string): HTMLSource {
   const html$ = vnode$.map(toHTML);
   html$.addListener({
     next: effect || noop,
     error: noop,
     complete: noop,
   });
   return new HTMLSource(html$, name);
 };
开发者ID:whitecolor,项目名称:cyclejs,代码行数:9,代码来源:makeHTMLDriver.ts

示例9: view

function view(state$: Stream<ViewState[]>): Stream<VNode> {
  return state$.map(state =>
    ul(
      state.map((model: ViewState) =>
        li(`${model.user.name} - ${model.homeworld ? model.homeworld.name : 'UNKNOWN'}`)
      )
    )
  )
}
开发者ID:jaketrent,项目名称:swapi-cycle-ts,代码行数:9,代码来源:index.ts

示例10: helixPiDriver

function helixPiDriver(sink$: Stream<Input>) {
  const worker = work(require("./worker"));

  const driver = makeWebWorkerDriver(worker);

  const stringifiedSink$ = sink$.map(event => JSON.stringify(event));

  return driver(stringifiedSink$).map(source => JSON.parse(source));
}
开发者ID:helix-pi,项目名称:helix-pi,代码行数:9,代码来源:editor.ts


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