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

TypeScript xstream.fromObservable函数代码示例

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

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



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

示例1: timeSource

  return function throttleAnimation<T>(inputStream: Stream<T>): Stream<T> {
    const source = timeSource();
    const stream = xs.fromObservable(inputStream);
    let animationListener: any = null;

    const throttledStream = xs.create<T>({
      start(listener) {
        let lastValue: any = null;
        let emittedLastValue = true;
        const frame$ = xs.fromObservable(source.animationFrames());

        const frameListener = {
          next(event: any) {
            if (!emittedLastValue) {
              listener.next(lastValue);
              emittedLastValue = true;
            }
          },
        };

        animationListener = {
          next(event: T) {
            lastValue = event;
            emittedLastValue = false;
          },

          error(err: Error) {
            listener.error(err);
          },

          complete() {
            frame$.removeListener(frameListener);
            listener.complete();
          },
        };

        stream.addListener(animationListener);
        frame$.addListener(frameListener);
      },

      stop() {
        if (animationListener) {
          stream.removeListener(animationListener);
        }
      },
    });

    return adapt(throttledStream);
  };
开发者ID:,项目名称:,代码行数:49,代码来源:


示例2: adapt

    return function debounceOperator<T>(inputStream: Stream<T>): Stream<T> {
      const state = {scheduledEntry: null};
      const stream = xs.fromObservable(inputStream);
      let debounceListener: any = null;

      const debouncedStream = xs.create<T>({
        start(listener: Listener<T>) {
          debounceListener = makeDebounceListener<T>(
            schedule,
            currentTime,
            debounceInterval,
            listener,
            state
          );

          stream.addListener(debounceListener);
        },

        stop() {
          if (debounceListener) {
            stream.removeListener(debounceListener);
          }
        },
      });

      return adapt(debouncedStream);
    };
开发者ID:,项目名称:,代码行数:27,代码来源:


示例3: sourcesWrapper

 return gear => {
     let state = cacheModel ? modelCache!.get(gear) : null
     if (!state) {
         const wrappedSources = sourcesWrapper(sources, gear)
         const actions = gear.intent ? gear.intent(wrappedSources) : defaultIntent(wrappedSources)
         state = xs.fromObservable(gear.model ? gear.model(actions) : defaultModel(actions))
             .replaceError((err: any) => {
                 if (cacheModel && modelCache) {
                     modelCache.delete(gear)
                 }
                 return xs.fromObservable(gear.catch ? gear.catch(err, actions) : defaultCatch(err, actions))
             })
             .remember()
         if (cacheModel) {
             modelCache!.set(gear, state)
         }
     }
     const views = teeth.reduce((accum, tooth) => {
         let view = state!.filter(toothFilter(tooth, (gear.teeth || {})[tooth])).map(toothView(tooth, (gear.teeth || {})[tooth]))
         const isolator = connectors.has(tooth)
             ? connectors.get(tooth)!.isolate || defaultConnector.isolate
             : defaultConnector.isolate
         if (isolator) {
             view = xs.fromObservable(isolator(sources, view, gear))
         }
         if (toothCombineGear) {
             view = view.map(v => [v, gear])
         }
         return Object.assign(accum, {
             [tooth]: view
         })
     },
                                {})
     return views
 }
开发者ID:WorldMaker,项目名称:cycle-gear,代码行数:35,代码来源:index.ts


示例4: return

    return (sources: any) => {
        let gears: Observable<Iterable<Gear<any, any>>>
        if (gearbox instanceof Function) {
            gears = gearbox(sources)
        } else {
            gears = gearbox
        }

        let spin = xs.fromObservable<Iterable<Gear<any, any>>>(gears)
            .map(spinGears(sources,
                           defaultIntent,
                           defaultModel,
                           cacheModel,
                           defaultCatch,
                           teeth,
                           toothFilter,
                           toothView,
                           cumulative,
                           sourcesWrapper,
                           defaultConnector,
                           connectors))
            .startWith([])

        if (cumulative) {
            spin = spin
                .map(spins => xs.fromArray(spins))
                .compose(flattenConcurrently)
                .remember()
        } else {
            spin = spin.remember()
        }

        const sinks = teeth.reduce((accum, tooth) => {
            let view: xs<any>
            if (cumulative) {
                view = spin
                    .map((gear: any) => gear[tooth])
                    .filter(toothView => !!toothView)
                    .compose(flattenConcurrently)
            } else {
                view = spin.map(spins => xs.fromArray(spins)
                        .map(gear => gear[tooth])
                        .filter(toothView => !!toothView)
                        .compose(flattenConcurrently))
                    .flatten()
            }
            const connector = connectors.get(tooth) || defaultConnector
            if (connector.fold) {
                view = view.fold(connector.reduce || defaultReduce, connector.init ? connector.init() : {})
            } else {
                view = view.map(([cur]: [any]) => cur)
            }
            return Object.assign(accum, {
                [sinkMap.has(tooth) ? sinkMap.get(tooth) : tooth]: adapt(view)
            })
        },
                                   {})

        return sinks
    }
开发者ID:WorldMaker,项目名称:cycle-gear,代码行数:60,代码来源:index.ts


示例5: collectionComponent

 return function collectionComponent(sources: any) {
   const name = opts.channel || 'state';
   const itemKey = opts.itemKey;
   const itemScope = opts.itemScope || defaultItemScope;
   const itemComp = opts.item;
   const state$ = xs.fromObservable((sources[name] as StateSource<S>).stream);
   const instances$ = state$.fold(
     (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]};
       }
     },
     {dict: new Map(), arr: []} as InternalInstances<Si>
   );
   return opts.collectSinks(new Instances<Si>(instances$));
 };
开发者ID:,项目名称:,代码行数:59,代码来源:


示例6: isolateSink

 public isolateSink(sink: any, scope: string): any {
   return adapt(
     xs.fromObservable<any>(sink).map((vnode: VNode) => {
       if (vnode.sel && vnode.sel.indexOf(SCOPE_PREFIX + scope) !== -1) {
         return vnode;
       } else {
         vnode.sel += `.${SCOPE_PREFIX}${scope}`;
         return vnode;
       }
     })
   );
 }
开发者ID:cyclejs,项目名称:cyclejs,代码行数:12,代码来源:mockDOMSource.ts


示例7: record

  return function record(stream: Stream<any>): Stream<any> {
    const recordedStream = xs.createWithMemory({
      start(listener) {
        xs.fromObservable(stream).addListener(
          recordListener(currentTime, listener)
        );
      },

      stop() {},
    });

    return adapt(recordedStream);
  };
开发者ID:ntilwalli,项目名称:cyclejs,代码行数:13,代码来源:record.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript xstream.merge函数代码示例发布时间:2022-05-25
下一篇:
TypeScript xstream.fromArray函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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