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


TypeScript isolate.default函數代碼示例

本文整理匯總了TypeScript中@cycle/isolate.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Counter

function Counter(sources: Sources): Sinks {
	const IncrementButton = isolate(Button);
	const DecrementButton = isolate(Button);

	let incrementButtonProps$ = xs.of<ButtonProps>({
    text: 'Increment', amount: 1
  }).remember();
	let decrementButtonProps$ = xs.of<ButtonProps>({
    text: 'Decrement', amount: -1
  }).remember();

	let incrementButton = IncrementButton({DOM: sources.DOM, props$: incrementButtonProps$});
	let decrementButton = DecrementButton({DOM: sources.DOM, props$: decrementButtonProps$});

	let count$ = xs.merge(incrementButton.delta$, decrementButton.delta$)
		.fold((acc, x) => acc + x, 0);

	return {
		DOM: xs.combine(count$, incrementButton.DOM, decrementButton.DOM)
      .map(([count, incrementVTree, decrementVTree]) =>
        div([
          incrementVTree,
					decrementVTree,
					h2('Clicks: ' + count),
        ])
      )
	};
}
開發者ID:mxstbr,項目名稱:cyclejs-counter,代碼行數:28,代碼來源:Counter.ts

示例2: BmiCalculator

function BmiCalculator(sources: Sources): Sinks {
  let WeightSlider = isolate(LabeledSlider);
  let HeightSlider = isolate(LabeledSlider);

  let weightProps$ = xs.of<LabeledSliderProps>({
    label: 'Weight', unit: 'kg', min: 40, initial: 70, max: 140
  }).remember();
  let heightProps$ = xs.of<LabeledSliderProps>({
    label: 'Height', unit: 'cm', min: 140, initial: 170, max: 210
  }).remember();

  let weightSlider = WeightSlider({DOM: sources.DOM, props$: weightProps$});
  let heightSlider = HeightSlider({DOM: sources.DOM, props$: heightProps$});

  let bmi$ = xs.combine(weightSlider.value$, heightSlider.value$)
    .map(([weight, height]) => {
      let heightMeters = height * 0.01;
      let bmi = Math.round(weight / (heightMeters * heightMeters));
      return bmi;
    }).remember();

  return {
    DOM: xs.combine(bmi$, weightSlider.DOM, heightSlider.DOM)
      .map(([bmi, weightVTree, heightVTree]) =>
        div([
          weightVTree,
          heightVTree,
          h2('BMI is ' + bmi)
        ])
      )
  };
}
開發者ID:DrUNE,項目名稱:cyclejs,代碼行數:32,代碼來源:BmiCalculator.ts

示例3: BmiCalculator

function BmiCalculator(sources: Sources): Sinks {
  const WeightSlider = isolate(LabeledSlider) as typeof LabeledSlider;
  const HeightSlider = isolate(LabeledSlider) as typeof LabeledSlider;

  const weightProps$ = xs.of({
    label: 'Weight', unit: 'kg', min: 40, initial: 70, max: 140,
  }).remember();
  const heightProps$ = xs.of({
    label: 'Height', unit: 'cm', min: 140, initial: 170, max: 210,
  }).remember();

  const weightSlider = WeightSlider({DOM: sources.DOM, props$: weightProps$});
  const heightSlider = HeightSlider({DOM: sources.DOM, props$: heightProps$});

  const bmi$ = xs.combine(weightSlider.value$, heightSlider.value$)
    .map(([weight, height]) => {
      const heightMeters = height * 0.01;
      const bmi = Math.round(weight / (heightMeters * heightMeters));
      return bmi;
    }).remember();

  const vdom$ = xs.combine(bmi$, weightSlider.DOM, heightSlider.DOM)
    .map(([bmi, weightVTree, heightVTree]) =>
      div([
        weightVTree,
        heightVTree,
        h2('BMI is ' + bmi),
      ]),
    );

  return {
    DOM: vdom$,
  };
}
開發者ID:joeldentici,項目名稱:cyclejs,代碼行數:34,代碼來源:BmiCalculator.ts

示例4: main

 function main(sources: {DOM: MainDOMSource}) {
   const first = isolate(Child, 'first')(sources);
   const second = isolate(Child, 'second')(sources);
   const oneChild = [first];
   const twoChildren = [first, second];
   const vnode$ = xs.periodic(50).take(1).startWith(-1)
     .map(i => i === -1 ? oneChild : twoChildren)
     .map(children =>
       xs.combine(...children.map(child => child.DOM))
         .map(childVNodes => div('.parent', childVNodes)),
     ).flatten();
   return {
     DOM: vnode$,
   };
 }
開發者ID:whitecolor,項目名稱:cyclejs,代碼行數:15,代碼來源:isolation.ts

示例5: Array

 (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]};
   }
 },
開發者ID:,項目名稱:,代碼行數:48,代碼來源:

示例6: main

    function main(sources: {state: StateSource<any>}) {
      assert(sources.state);
      assert(sources.state.stream);
      const expected = [[3, 5, 6], [3, 15, 6], [3, 6]];
      sources.state.stream.addListener({
        next(x) {
          assert.deepEqual(x, expected.shift());
          calledMain += 1;
        },
        error(e) {
          done(e);
        },
        complete() {},
      });

      const childSinks = isolate(secondEntry, 1)(sources);
      assert(childSinks.state);
      const childReducer$ = childSinks.state;

      const parentReducer$ = xs.of(function initReducer(prevState: any): any {
        return [3, 5, 6];
      });
      const reducer$ = xs.merge(parentReducer$, childReducer$) as Stream<
        Reducer<any>
      >;

      return {
        state: reducer$,
      };
    }
開發者ID:,項目名稱:,代碼行數:30,代碼來源:

示例7: Main

    function Main(sources: {state: StateSource<any>}) {
      sources.state.stream.addListener({
        next(x) {
          assert.deepEqual(x.list, expected.shift());
        },
        error(e) {
          done(e.message);
        },
        complete() {
          done('complete should not be called');
        },
      });

      const childSinks = isolate(List, 'list')(sources);
      const childReducer$ = childSinks.state;

      const initReducer$ = xs.of(function initReducer(prevState: any): any {
        return {list: [{val: 3}]};
      });

      const addReducer$ = xs
        .of(function addSecond(prev: any) {
          return {list: prev.list.concat({val: null})};
        })
        .compose(delay(100));

      const parentReducer$ = xs.merge(initReducer$, addReducer$);
      const reducer$ = xs.merge(parentReducer$, childReducer$) as Stream<
        Reducer<any>
      >;

      return {
        state: reducer$,
      };
    }
開發者ID:,項目名稱:,代碼行數:35,代碼來源:

示例8: main

function main(sources: Sources): Sinks {
  const stateUpdate$ = sources.websocket.get('state-update')
    .map(msg => msg.data as BootstrapMessage)
  const board = isolate(Board)(sources, stateUpdate$)

  const boardWebsocket$ = Stream.merge(
    board.moveNote$.map(noteEvent => ({
      type: 'move-note',
      data: noteEvent,
    })),
    board.addNote$.mapTo({ type: 'add-note' }),
    board.editNote$.map(({ id, label }) => ({
      type: 'change-note-label',
      data: { id, label }
    })),
    board.noteDelete$.map(id => ({
      type: 'delete-note',
      data: { id }
    }))
  )

  return {
    DOM: board.DOM,
    websocket: Stream.merge(boardWebsocket$, Stream.of({ type: 'init' }))
      .debug('websocket$'),
    preventDefault: board.preventDefault,
    focus: board.focus,
  }
}
開發者ID:JamesHageman,項目名稱:xstream-scrumbler,代碼行數:29,代碼來源:index.ts


注:本文中的@cycle/isolate.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。