當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript xstream.fromObservable函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。