Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const App = R(({events}) => {
const inc$ = Observable.fromEvent(events, "inc-click").map(() => +1)
const dec$ = Observable.fromEvent(events, "dec-click").map(() => -1)
// also React onChange is supported
const text$ = Observable.fromEvent(events, "text-change")
.map(e => e.target.value)
.startWith("tsers")
.shareReplay()
const counter$ =
inc$.merge(dec$)
.startWith(0)
.scan((val, d) => val + d, 0)
.shareReplay()
const style$ =
Observable.combineLatest([text$, counter$])
.map(([text, counter]) => text.length === counter ? "red" : "black")
.map(color => ({color}))
// You can emit events from reactive components by giving an object
const App = R(({events}) => {
const inc$ = Observable.fromEvent(events, "inc-click").map(() => +1)
const dec$ = Observable.fromEvent(events, "dec-click").map(() => -1)
// also React onChange is supported
const text$ = Observable.fromEvent(events, "text-change")
.map(e => e.target.value)
.startWith("tsers")
.shareReplay()
const counter$ =
inc$.merge(dec$)
.startWith(0)
.scan((val, d) => val + d, 0)
.shareReplay()
const style$ =
Observable.combineLatest([text$, counter$])
this.osc = dgram.createSocket("udp4");
this.osc.on("listening", () => {
this.processEvents.onNext(udpListening);
});
this.osc.on("close", e => {
this.processEvents.onNext("udp closed: " + e);
this.disconnect();
});
// pipe events to this.receive
this._serverObservers.oscMessage = Observable.fromEvent(this.osc, "message", msgbuf => unpackMessage(msgbuf));
this._serverObservers.oscMessage.subscribe(e => this.receive.onNext(parseMessage(e)));
this._serverObservers.oscError = Observable.fromEvent(this.osc, "error");
this._serverObservers.oscError.subscribe(e => {
this.receive.onError(e);
reject(e);
});
// this will trigger a response from server
// which will cause a udp listening event.
// After server responds then we are truly connected.
this.callAndResponse(notify()).then(() => {
resolve(this);
});
});
}
return new Promise((resolve, reject) => {
const udpListening = "udp is listening";
this.osc = dgram.createSocket("udp4");
this.osc.on("listening", () => {
this.processEvents.onNext(udpListening);
});
this.osc.on("close", e => {
this.processEvents.onNext("udp closed: " + e);
this.disconnect();
});
// pipe events to this.receive
this._serverObservers.oscMessage = Observable.fromEvent(this.osc, "message", msgbuf => unpackMessage(msgbuf));
this._serverObservers.oscMessage.subscribe(e => this.receive.onNext(parseMessage(e)));
this._serverObservers.oscError = Observable.fromEvent(this.osc, "error");
this._serverObservers.oscError.subscribe(e => {
this.receive.onError(e);
reject(e);
});
// this will trigger a response from server
// which will cause a udp listening event.
// After server responds then we are truly connected.
this.callAndResponse(notify()).then(() => {
resolve(this);
});
});
}
function intent (DOM) {
const mousePosition$ = DOM.select('.stream').events('mousemove')
.map(getMousePosition)
.startWith({x: 0, y: 0})
const click$ = DOM.select('.stream').events('mousedown');
const release$ = Observable.fromEvent(document.body, 'mouseup');
const dragging$ = Observable.merge(
click$.map(_ => true),
release$.map(_ => false)
).startWith(false);
const playingClick$ = DOM.select('.pause').events('click')
.scan((previous, _) => !previous, true)
.startWith(true);
const playing$ = Observable.combineLatest(
dragging$,
playingClick$,
(dragging, playingClick) => {
if (dragging) {
return false;
.flatMap(event => $.fromEvent(player, event))
.pluck('target');
presses (key) {
let keypress$ = Observable.fromEvent(document.body, 'keypress');
if (key) {
const code = keycode(key);
keypress$ = keypress$.filter(event => event.keyCode === code);
}
return keypress$;
}
}
subscribe(
onNext: (value: { type: string; payload: any }) => void,
onError?: (value: { type: string; payload: any }) => void,
onComplete?: () => void,
): Disposable {
const msgs = Observable.fromEvent(this, "msg", msg => {
return {
type: "msg",
payload: msg,
};
});
const bundles = Observable.fromEvent(this, "bundle", bundle => {
return {
type: "bundle",
payload: bundle,
};
});
const combo = msgs.merge(bundles);
return combo.subscribe(onNext, onError, onComplete);
}
}
function listenForResize(document, window) {
return Observable.fromEvent(window, 'resize')
.debounce(250)
.startWith({})
.map(() => getWindowSize(document, window));
}
changes(): Observable {
return Observable.fromEvent(this.ringpop, 'ringChanged');
}