本文整理汇总了TypeScript中@cycle/run/lib/adapt.setAdapt函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setAdapt函数的具体用法?TypeScript setAdapt怎么用?TypeScript setAdapt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setAdapt函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should allow listening to link clicks and change route', function(done) {
setAdapt(x => x);
const historyDriver = makeHistoryDriver();
const sink = xs.never();
const history$ = captureClicks(historyDriver)(sink);
const sub = history$
.compose(debounce(5))
.drop(1)
.subscribe({
next: (location: Location) => {
assert.strictEqual(location.pathname, '/test');
sub.unsubscribe();
sink.shamefullySendComplete();
done();
},
error: err => {},
complete: () => {},
});
const a = document.createElement('a');
a.href = '/test';
document.body.appendChild(a);
setTimeout(() => {
a.click();
}, 10);
});
示例2: beforeEach
beforeEach(function() {
setAdapt(x => x);
});
示例3: keyof
import {
setup as coreSetup,
DisposeFunction,
Driver,
FantasyObservable,
Sources,
Sinks,
CycleProgram,
} from '@cycle/run';
export type Drivers<So extends Sources, Si extends Sinks> = {
[P in keyof (So & Si)]: Driver<FantasyObservable, any>
};
setAdapt(function adaptXstreamToRx(stream: Stream<any>): Observable<any> {
return from(stream as any);
});
/**
* Takes a `main` function and circularly connects it to the given collection
* of driver functions.
*
* **Example:**
* ```js
* import run from '@cycle/rxjs-run';
* const dispose = run(main, drivers);
* // ...
* dispose();
* ```
*
* The `main` function expects a collection of "source" Observables (returned
示例4: keyof
import {
setup as coreSetup,
DisposeFunction,
Driver,
FantasyObservable,
Sources,
Sinks,
CycleProgram,
} from '@cycle/run';
export type Drivers<So extends Sources, Si extends Sinks> = {
[P in keyof (So & Si)]: Driver<FantasyObservable, any>
};
setAdapt(function adaptXstreamToMost(stream: Stream<any>): MostStream<any> {
return most.from(stream as any);
});
/**
* Takes a `main` function and circularly connects it to the given collection
* of driver functions.
*
* **Example:**
* ```js
* import run from '@cycle/most-run';
* const dispose = run(main, drivers);
* // ...
* dispose();
* ```
*
* The `main` function expects a collection of "source" streams (returned from
示例5: setAdapt
// tslint:disable-next-line
import 'mocha';
import 'symbol-observable'; // tslint:disable-line
import * as assert from 'assert';
import {of, from, Observable} from 'rxjs';
import isolate from '../src/index';
import {setAdapt} from '@cycle/run/lib/adapt';
setAdapt(from as any);
describe('isolate', function() {
beforeEach(function() {
(isolate as any).reset();
});
it('should be a function', function() {
assert.strictEqual(typeof isolate, 'function');
});
it('should throw if first argument is not a function', function() {
assert.throws(() => {
isolate('not a function' as any);
}, /First argument given to isolate\(\) must be a 'dataflowComponent' function/i);
});
it('should throw if second argument is null', function() {
function MyDataflowComponent() {}
assert.throws(() => {
isolate(MyDataflowComponent, null);
}, /Second argument given to isolate\(\) must not be null/i);
});
示例6: before
before(() => setAdapt(stream => Observable.from(stream)));
示例7: setAdapt
import * as most from 'most';
import {Stream} from 'most';
import {setAdapt} from '@cycle/run/lib/adapt';
import {mockTimeSource as mockTimeSourceUntyped} from './src/mock-time-source';
import {timeDriver as timeDriverUntyped} from './src/time-driver';
import {Frame} from './src/animation-frames';
setAdapt(stream => most.from(stream as any));
type Operator = <T>(stream: Stream<T>) => Stream<T>;
interface TimeSource {
animationFrames(): Stream<Frame>;
delay(delayTime: number): Operator;
debounce(period: number): Operator;
throttle(period: number): Operator;
periodic(period: number): Stream<number>;
throttleAnimation: Operator;
}
interface MockTimeSource extends TimeSource {
diagram(str: string, values?: Object): Stream<any>;
record(stream: Stream<any>): Stream<Array<any>>;
assertEqual(actual: Stream<any>, expected: Stream<any>): void;
run(cb?: (err?: Error) => void): void;
}
function mockTimeSource(args?: Object): MockTimeSource {
return mockTimeSourceUntyped(args);
}
示例9: before
before(() => setAdapt(stream => most.from(stream as any)));
示例10: beforeEach
beforeEach(function() {
setAdapt(x => Observable.from(x as any));
if (window.history) {
window.history.replaceState(undefined, undefined, '/');
}
});