Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
),
});
const lastSentReply$ = actions.sentReply$
.filter(res => 'id' in res)
.map(res => res.id)
.startWith(false);
/**
* Http write effects, including:
* - votes requests
* - comments requests
*/
const http$ = xs.merge(
// New votes
actions.voting$
.compose(sampleCombine(actions.authToken$))
.map(([{ type, intent, id }, withAuth]) => ({
method: 'POST',
type: 'application/json',
url: `${Anzu.layer}vote/${type}/${id}`,
category: 'vote',
send: { direction: intent },
headers: withAuth({}),
})),
// Replies sent
actions.reply$
.compose(sampleCombine(actions.replyContent$, actions.authToken$))
.map(([{ type, id }, content, withAuth]) => ({
method: 'POST',
type: 'application/json',
url: `${Anzu.layer}comments/${id}?type=${type}`,
export function Timer(sources: Sources) {
// Initialze if used alone - use parent provided state is present
const defaultReducer$ = xs.of(prev => prev || { running: false });
const i$ = sources.time.periodic(100)
.map(x => x + 1)
.startWith(0)
.remember();
const start$ = sources.DOM.select('.start').events('click')
.compose(sampleCombine(i$))
.map(eventI => state => ({ ...state, running: true, x: eventI[1] - state.x }));
const stop$ = sources.DOM.select('.stop').events('click')
.compose(sampleCombine(i$))
.map(eventI => state => ({ ...state, running: false, x: eventI[1] - state.x }));
const reset$ = sources.DOM.select('.reset').events('click')
.mapTo(state => ({ ...state, running: false, x: 0 }));
return {
DOM: view(sources.onion.state$, i$),
onion: xs.merge(defaultReducer$, start$, stop$, reset$)
};
}
}
},
error (err) {
console.error(err);
},
complete () {}
});
const restartEnabled$ = DOM.select('.instant-checkbox').events('change')
.map(ev => ev.target.checked)
.startWith(true);
xs.merge(props, code$)
.compose(debounce(300))
.map(transformES6(error$))
.compose(sampleCombine(restartEnabled$))
.addListener({
next ([{code}, restartEnabled]) {
runOrRestart(code, restartEnabled)
},
error (err) {
console.error(err);
},
complete () {}
})
function runOrRestart(code, restartEnabled) {
if (sources) {
sources.dispose();
}
if (sinks) {
export default function addition(sources: Sources): Sinks {
const state$ = sources.onion.state$;
const actions = intent(sources.screen);
const addDat$ = actions.submit$
.compose(sampleCombine(state$))
.map(([_, state]) => state.textInput.startsWith('dat://')
? state.textInput.substr(6)
: state.textInput
);
const request$ = addDat$.map(datHash => ({
url: "/datSync",
method: "POST",
send: { datKey: datHash },
}));
const dismissThisScreen$ = addDat$.mapTo({
type: "dismissModal",
} as DismissModalCommand);
const reducer$ = model(actions);
export function central(sources: Sources): Sinks {
const topBarSinks: TBSinks = isolate(topBar, {
'*': 'topBar',
state: topBarLens,
})(sources);
const actions = intent(sources.screen);
const scrollToTop$ = actions.changeTab$
.compose(sampleCombine(sources.state.stream))
.filter(([i, state]) => state.currentTab === 0 && i === 0)
.mapTo(null);
const fabPress$: Stream = sources.screen
.select('fab')
.events('pressItem');
const publicTabSinks = isolate(publicTab, {
state: publicTabLens,
'*': 'publicTab',
})({...sources, scrollToTop: scrollToTop$, fab: fabPress$}) as PublicTabSinks;
const connectionsTabSinks = isolate(connectionsTab, {
state: connectionsTabLens,
'*': 'connectionsTab',
})({...sources, fab: fabPress$}) as ConnectionsTabSinks;
function speech(speech$: Stream, state$: Stream): Stream {
return speech$
.compose(sampleCombine(state$))
.map(([_, s]: [any, State]) => s.text);
}
({
type: 'push',
layout: {
component: {
name: Screens.Profile,
passProps: {
selfFeedId: state.selfFeedId,
feedId: ev.authorFeedId,
},
options: profileScreenNavOptions,
},
},
} as Command),
);
const toThread$ = actions.goToThread$.compose(sampleCombine(state$)).map(
([ev, state]) =>
({
type: 'push',
layout: {
component: {
name: Screens.Thread,
passProps: {
selfFeedId: state.selfFeedId,
rootMsgId: ev.rootMsgId,
replyToMsgId: ev.replyToMsgId,
},
options: threadScreenNavOptions,
},
},
} as Command),
);
...state,
message: message.sent ? '' : message.payload,
}));
const onlineR$ = actions.online$.map(list => state => ({
...state,
online: list,
}));
/**
* Transform sent messages to packed list of actual commands.
*
* @type {Stream<u>|Stream}
*/
const sent$ = actions.msg$
.filter(message => message.sent)
.compose(sampleCombine(user$))
.map(([msg, user]) => message(cmessage(user, msg, new Date())));
const sentLists$ = sent$.map(message => list(message));
const messagesR$ = xs
.merge(actions.messages$, sentLists$)
.map(packed => state => {
const channel = packed.channel || false;
let list =
channel == false ||
state.channel == channel ||
channel === 'log'
? state.list.concat(packed.list)
: state.list;
if (
(channel == false ||</u>
publishReply$,
togglePreview$: topBarPreviewToggle$,
updatePostText$: reactSource
.select('composeInput')
.events('changeText') as Stream,
updateMentionQuery$: reactSource
.select('mentionInput')
.events('changeText') as Stream,
updateSelection$,
suggestMention$: updateSelection$
.compose(sampleCombine(state$))
.map(
([selection, state]) =>
[parseMention(state.postText, selection), selection] as [
ReturnType,
typeof selection,
],
),
chooseMention$: reactSource
.select('suggestions')
.events('pressAccount') as Stream<{id: FeedId; name: string}>,
cancelMention$: reactSource.select('mentions-cancel').events('press'),
openContentWarning$: reactSource
.select('content-warning')
function navigation(actions: Actions, state$: Stream) {
const pop$ = actions.goBack$.mapTo({
type: 'pop',
} as PopCommand);
const toProfile$ = actions.goToProfile$.compose(sampleCombine(state$)).map(
([ev, state]) =>
({
type: 'push',
layout: {
component: {
name: Screens.Profile,
passProps: {
selfFeedId: state.selfFeedId,
feedId: ev.id,
},
options: profileScreenNavOptions,
},
},
} as Command),
);