Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getConditionalCmp (cond, getCmp) {
const cond$ = isStream(cond)
? cond
// xs.of() is insufficient, because it must be a memory stream
: xs.create().startWith(cond)
if (!(cond$ instanceof MemoryStream)) {
console.warn('Conditional stream should be a MemoryStream')
}
return getDynamicCmp (
cond$.fold(
(acc, next) => ({ cond: next, key: String(Boolean(next)) }),
{ cond: false, key: 'false' }
),
next => getCmp(next.cond)
)
}
function restartableDriver (sink$, Time) {
const filteredSink$ = xs.create();
const lastSinkEvent$ = xs.createWithMemory();
if (sink$) {
if (isReplaying() && replayOnlyLastSink) {
lastSinkEvent$.map(lastEvent => finishedReplay$.mapTo(lastEvent)).flatten().take(1).addListener(subscribe((event) => {
filteredSink$.shamefullySendNext(event);
}));
}
if (pauseSinksWhileReplaying) {
sink$.compose(pausable(pause$)).filter(() => !isReplaying()).addListener({
next: (ev) => filteredSink$.shamefullySendNext(ev),
error: (err) => console.error(err),
complete: () => {}
});
} else {
create: (api: any) => {
const stream: Stream = xs.create();
return nest({
'sbot.hook': {
publish: (msg: Msg) => {
stream.shamefullySendNext(msg);
},
publishStream: () => stream,
},
});
},
};
return () => {
return xs.create({
start: listener => {
websocket.onmessage = (msg : MessageEvent) => listener.next(msg);
},
stop: () => {}
})
.map((msg : MessageEvent) => {
const json : any = JSON.parse(msg.data);
return {
...json,
time: new Date(json.time)
};
});
};
}
function List(sources) {
const proxyItemRemove$ = xs.create();
const action$ = intent(sources.DOM, proxyItemRemove$);
const itemWrapper = makeItemWrapper(sources.DOM);
const items$ = model(action$, itemWrapper);
const itemRemove$ = items$
.map(items => xs.merge(...items.map(item => item.Remove)))
.flatten();
proxyItemRemove$.imitate(itemRemove$);
const vtree$ = view(items$);
return {
DOM: vtree$
};
}
export default function Menubar({
DOM: domSource,
state: state$,
appHistory: appHistory$,
}: Sources): Sinks {
const nextActiveCategoryProxy$ = xs.create()
const activeCategory$ = nextActiveCategoryProxy$.dropRepeats().startWith(null)
const closeWhenBlur$ = domSource
.select('.menubar')
.events('blur')
.mapTo(null)
const closeWhenMakeIntent$ = domSource
.select('.menu-item')
.events('click')
.filter(e => !e.ownerTarget.classList.contains('disabled'))
.mapTo(null)
const clickToToggleCategory$ = domSource
.select('.category .title')
this.internalListener = (message: Message) => {
if (this.isStreamPaused) {
return;
}
listener.next(message as T);
};
this.topic.subscribe(this.internalListener);
},
stop: () => {
this.topic.unsubscribe(this.internalListener!);
this.removeRosHealthHooks();
},
};
this.stream = this.hasMemory
? xs.createWithMemory(this.producer)
: xs.create(this.producer);
this.isStreamLive = true;
this.rosConnectionHook = () => {
if (this.isStreamLive) {
return;
}
this.stream = this.hasMemory
? xs.createWithMemory(this.producer)
: xs.create(this.producer);
this.isStreamLive = true;
this.listeners.forEach(listener => {
this.stream.addListener(listener);
});
};
this.ros.on('connection', this.rosConnectionHook);
}
),
);
this.selfReplies$ = this.ssb$.map(ssb => (opts?: any) =>
pull(
ssb.createUserStream({id: ssb.id, ...opts}),
pull.filter(isReplyPostMsg),
pull.asyncMap(mutateMsgWithLiveExtras(ssb)),
),
);
this.publishHook$ = this.ssb$
.map(ssb => ssb.hooks.publishStream())
.flatten();
this.acceptInviteResponse$ = xs.create();
this.acceptDhtInviteResponse$ = xs.create();
this.peers$ = this.ssb$
.map(ssb =>
xsFromPullStream>(ssb.conn.peers())
.map(peers =>
backoff(1e3, 2, 60e3)
.startWith(0)
.map(() => {
for (const [, data] of peers) {
if (data.key) ssb.cachedAbout.invalidate(data.key);
}
return peers;
}),
)
.flatten()
);
this.selfReplies$ = this.ssb$.map(ssb => (opts?: any) =>
pull(
ssb.createUserStream({id: ssb.id, ...opts}),
pull.filter(isReplyPostMsg),
pull.asyncMap(mutateMsgWithLiveExtras(ssb)),
),
);
this.publishHook$ = this.ssb$
.map(ssb => ssb.hooks.publishStream())
.flatten();
this.acceptInviteResponse$ = xs.create();
this.acceptDhtInviteResponse$ = xs.create();
this.peers$ = this.ssb$
.map(ssb =>
xsFromPullStream>(ssb.conn.peers())
.map(peers =>
backoff(1e3, 2, 60e3)
.startWith(0)
.map(() => {
for (const [, data] of peers) {
if (data.key) ssb.cachedAbout.invalidate(data.key);
}
return peers;
}),
)
.flatten()
.map(peersArr =>