本文整理汇总了TypeScript中rxjs.Subscriber.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Subscriber.create方法的具体用法?TypeScript Subscriber.create怎么用?TypeScript Subscriber.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rxjs.Subscriber
的用法示例。
在下文中一共展示了Subscriber.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createSplashSubscriber
export function createSplashSubscriber() {
let win: BrowserWindow;
return Subscriber.create(
() => {
win = new BrowserWindow({
width: 565,
height: 233,
useContentSize: true,
title: "loading",
frame: false,
show: false
});
const index = join(__dirname, "..", "static", "splash.html");
win.loadURL(`file://${index}`);
win.once("ready-to-show", () => {
win.show();
});
},
err => {
console.error(err);
},
() => {
// Close the splash page when completed
if (win) {
win.close();
}
}
);
}
示例2: it
it('should be extensible with a new subscriber', () => {
const stub = sinon.stub();
ReactiveApp.defaultErrorHandler = Subscriber.create(stub);
const err = new Error('testing');
ReactiveApp.defaultErrorHandler.next(err);
stub.should.have.been.calledOnce;
stub.should.have.been.calledWith(err);
});
示例3: logNext
const logObs = (msg:string) => Subscriber.create(
function logNext(x) {
console.log({[`next ${msg}`]: x})
},
function logError(e) {
console.log({[`ERROR! ${msg}`]: e});
},
function logCompleted() {
console.log(`completed ${msg}`);
}
);
示例4: _mount
private _mount(mountpoint: Element): Rx.Subscription {
const observer: Rx.Subscriber<SidebarViewState> = Rx.Subscriber.create((model: SidebarViewState) => {
const view = React.createElement(Sidebar, {
model,
});
ReactDOM.render(view, mountpoint);
}, () => { }, () => {
ReactDOM.unmountComponentAtNode(mountpoint);
});
return this._viewmodel.subscribe(observer);
}
示例5: _mount
private _mount(mountpoint: Element): Rx.Subscription {
const observer: Rx.Subscriber<ConnectionValue> = Rx.Subscriber.create((data: ConnectionValue) => {
const view = React.createElement(ConnectSettingWindow, {
viewmodel: this._store.viewmodel(),
action: this._action,
data: data,
});
ReactDOM.render(view, mountpoint);
}, () => { }, () => {
ReactDOM.unmountComponentAtNode(mountpoint);
});
return this._store.subscribe(observer);
}
示例6: fromAddress
static fromAddress(address: string): Observable<MessageEvent> {
const ws = new WebSocket(address);
const observable = Observable.create((obs: Observer<any>) => {
ws.onmessage = obs.next.bind(obs);
ws.onerror = obs.error.bind(obs);
ws.onclose = obs.complete.bind(obs);
return ws.close.bind(ws);
});
const observer = Subscriber.create((data) => {
if (ws.readyState === WebSocket.OPEN) { ws.send(data); }
});
return Subject.create(observer, observable);
}
示例7: it
it('should be possible to unsubscribe in the middle of the iteration', (done) => {
const expected = [10, 20, 30];
const subscriber = Subscriber.create(
(x) => {
expect(x).to.equal(expected.shift());
if (x === 30) {
subscriber.unsubscribe();
done();
}
}, (x) => {
done(new Error('should not be called'));
}, () => {
done(new Error('should not be called'));
}
);
fromIterable([10, 20, 30, 40, 50, 60], undefined).subscribe(subscriber);
});
示例8: constructor
constructor(private store: Store<AppState>) {
this.ccypairs = this.store
.select((s: AppState) => s.underlyings.ccypairs)
.map((ccypairs: CcyPair[]) => ccypairs.filter((c: CcyPair) => !c.active));
this.tickers = this.store
.select((s: AppState) => s.underlyings.values)
.flatMap((v: CcyPairValues) => {
return this.store
.select((s: AppState) => s.underlyings.ccypairs)
.map((ccypairs: CcyPair[]) => {
return ccypairs
.filter((c: CcyPair) => c.active)
.map((c: CcyPair) => v[c.value]);
});
});
this.tickers.subscribe((val: any) => console.log(val));
this.onCcypairDropped = Subscriber.create((val: any) => {
this.store.dispatch(setCcypairActive(val.value, true));
});
}
示例9: fromIterable
'but is unsubscribed early', (done) => {
const expected = [10, 20, 30, 40];
const source = fromIterable(
[10, 20, 30, 40],
queueScheduler
);
const subscriber = Subscriber.create(
(x) => {
expect(x).to.equal(expected.shift());
if (x === 30) {
subscriber.unsubscribe();
done();
}
}, (x) => {
done(new Error('should not be called'));
}, () => {
done(new Error('should not be called'));
});
source.subscribe(subscriber);
});
示例10: uuid
export const createMainChannelFromSockets = (
sockets: {
[name: string]: moduleJMP.Socket;
},
header: HeaderFiller = {
session: uuid(),
username: getUsername()
},
jmp = moduleJMP
): Channels => {
// The mega subject that encapsulates all the sockets as one multiplexed
// stream
const outgoingMessages = Subscriber.create<JupyterMessage>(
message => {
// There's always a chance that a bad message is sent, we'll ignore it
// instead of consuming it
if (!message || !message.channel) {
console.warn("message sent without a channel", message);
return;
}
const socket = sockets[message.channel];
if (!socket) {
// If, for some reason, a message is sent on a channel we don't have
// a socket for, warn about it but don't bomb the stream
console.warn("channel not understood for message", message);
return;
}
try {
const jMessage = new jmp.Message({
// Fold in the setup header to ease usage of messages on channels
header: { ...message.header, ...header },
parent_header: message.parent_header,
content: message.content,
metadata: message.metadata,
buffers: message.buffers
});
socket.send(jMessage);
} catch (err) {
console.error("Error sending message", err, message);
}
},
undefined, // not bothering with sending errors on
() =>
// When the subject is completed / disposed, close all the event
// listeners and shutdown the socket
Object.keys(sockets).forEach(name => {
const socket = sockets[name];
socket.removeAllListeners();
if (socket.close) socket.close();
})
);
// Messages from kernel on the sockets
const incomingMessages: Observable<JupyterMessage> = merge(
// Form an Observable with each socket
...Object.keys(sockets).map(name => {
const socket = sockets[name];
// fromEvent typings are broken. socket will work as an event target.
return fromEvent(
// Pending a refactor around jmp, this allows us to treat the socket
// as a normal event emitter
(socket as unknown) as FromEventTarget<JupyterMessage>,
"message"
).pipe(
map(
(body: JupyterMessage): JupyterMessage => {
// Route the message for the frontend by setting the channel
const msg = { ...body, channel: name };
// Conform to same message format as notebook websockets
// See https://github.com/n-riesco/jmp/issues/10
delete (msg as any).idents;
return msg;
}
),
publish(),
refCount()
);
})
).pipe(
publish(),
refCount()
);
const subject: Subject<JupyterMessage> = Subject.create(
outgoingMessages,
incomingMessages
);
return subject;
};