Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function drags ({mouseDowns$, mouseUps$, mouseMoves$, touchStarts$, touchEnds$, longTaps$, touchMoves$}, settings) {
touchMoves$ = touchMoves$.filter(t => t.touches.length === 1)
const drags$ = merge(
mouseDrags(mouseDowns$, mouseUps$, mouseMoves$, settings),
touchDrags(touchStarts$, touchEnds$, touchMoves$, settings)
)
// .merge(merge(touchEnds$, mouseUps$).map(undefined))
// .tap(e=>console.log('dragMoves',e))
// .takeUntil(longTaps$) // .repeat() // no drag moves if there is a context action already taking place
return drags$
}
function zooms ({touchStarts$, touchMoves$, touchEnds$, wheel$}, settings) {
const zooms$ = merge(
pinchZooms({touchStarts$, touchMoves$, touchEnds$}, settings), // for Android (no gestureXX events)
wheel$
)
.map(x => x * settings.zoomMultiplier)
return zooms$
}
}
options = Object.assign({}, defaults, options)
const {passiveEventsHandlers, preventScroll, preventMenu} = options
const mouseDowns$ = fromEvent('mousedown', targetEl, {passive: passiveEventsHandlers, capture: false})
const mouseUps$ = fromEvent('mouseup', targetEl, {passive: passiveEventsHandlers, capture: false})
// const mouseLeaves$ = fromEvent('mouseleave', targetEl, {passive:true,capture:false}).merge(fromEvent('mouseout', targetEl, {passive:true,capture:false}))
const mouseMoves$ = fromEvent('mousemove', targetEl, {passive: passiveEventsHandlers, capture: false}) // .takeUntil(mouseLeaves$) // altMouseMoves(fromEvent(targetEl, 'mousemove')).takeUntil(mouseLeaves$)
const rightClicks$ = fromEvent('contextmenu', targetEl, {passive: !options.preventMenu, capture: false})
const touchStarts$ = fromEvent('touchstart', targetEl, {passive: passiveEventsHandlers, capture: false})
const touchMoves$ = fromEvent('touchmove', targetEl, {passive: passiveEventsHandlers, capture: false})
const touchEnds$ = fromEvent('touchend', targetEl, {passive: passiveEventsHandlers, capture: false})
const pointerDowns$ = merge(mouseDowns$, touchStarts$) // mouse & touch interactions starts
const pointerUps$ = merge(mouseUps$, touchEnds$) // mouse & touch interactions ends
const pointerMoves$ = merge(mouseMoves$, touchMoves$.filter(t => t.touches.length === 1))
function preventAllScrolls (targetEl) {
fromEvent('mousewheel', targetEl, {passive: false, capture: false}).forEach(preventDefault)
fromEvent('DOMMouseScroll', targetEl, {passive: false, capture: false}).forEach(preventDefault)
fromEvent('wheel', targetEl, {passive: false, capture: false}).forEach(preventDefault)
fromEvent('touchmove', targetEl, {passive: false, capture: false}).forEach(preventDefault)
}
if (preventScroll) {
preventAllScrolls(targetEl, {passive: passiveEventsHandlers, capture: false})
}
if (preventMenu) {
rightClicks$.forEach(preventDefault)
}
function bootstrapBundles (entryPointDefs, splitPointDefs) {
const entryPointBundles = most.generate(entries, entryPointDefs)
.map(([srcPath, bundleDef]) => this.bootstrapBundle(srcPath, bundleDef, true))
.await();
const splitPointBundles = most.generate(entries, splitPointDefs)
.map(([srcPath, splitDef]) => this.bootstrapBundle(srcPath, splitDef, false))
.await();
return most.merge(entryPointBundles, splitPointBundles);
}
_bindToTableStream() {
this.stream$ = most.merge(this.stream$, most.fromEvent(MESSAGE, this._tee));
}
function respond(actions, updates) {
const streams = xmap(updates, (value, key) => update(actions[key], value));
return merge(...streams);
}
text: form.querySelector('[name="text"]').value,
thread: form.querySelector('[name="thread"]').value || cuid.slug()
}))
.filter(({text}) => text)
.map(variables => ({mutation: 'postMessage', variables}))
)
let notify$ = most.merge(
response$
.filter(({errors}) => errors && errors.length)
.flatMap(({errors}) => most.from(errors.map(e => e.message)))
)
return {
DOM: vtree$,
ROUTER: most.merge(
DOM.select('ul.thread').events('click')
.map(e => `/thread/${e.ownerTarget.id}`),
postMessage$.map(message => `/thread/${message.thread}`)
),
GRAPHQL: graphql$,
NOTIFICATION: notify$,
STORAGE: most.merge(
DOM.select('form.create [name="text"]').events('input')
.map(e => ({
[`typed.${e.target.parentNode.querySelector('[name="thread"]').value}`]:
e.target.value
})),
messageSubmit$
.map(form => ({
text: form.querySelector('[name="text"]').value,
thread: form.querySelector('[name="thread"]').value
let notify$ = most.merge(
response$
.filter(({errors}) => errors && errors.length)
.flatMap(({errors}) => most.from(errors.map(e => e.message)))
)
return {
DOM: vtree$,
ROUTER: most.merge(
DOM.select('ul.thread').events('click')
.map(e => `/thread/${e.ownerTarget.id}`),
postMessage$.map(message => `/thread/${message.thread}`)
),
GRAPHQL: graphql$,
NOTIFICATION: notify$,
STORAGE: most.merge(
DOM.select('form.create [name="text"]').events('input')
.map(e => ({
[`typed.${e.target.parentNode.querySelector('[name="thread"]').value}`]:
e.target.value
})),
messageSubmit$
.map(form => ({
text: form.querySelector('[name="text"]').value,
thread: form.querySelector('[name="thread"]').value
}))
.map(v => ({[`typed.${v.thread}`]: ''}))
)
}
}
export function LocalStorage(sinks: LocalStorageSinks): LocalStorageSources {
const { localStorage$ } = sinks
const localStorageEvent$: Stream =
filter(isLocalStorageEvent, fromEvent('storage', window, true))
const storage$: Stream =
multicast(merge(
constant(window.localStorage, tap(storageAction, localStorage$)),
constant(window.localStorage, localStorageEvent$),
))
drain(storage$)
const getItem = createGetItem(storage$)
const length = createLength(storage$)
const localStorage: LocalStorageSource =
{
getItem,
length,
}
return { localStorage }
function preventAllScrolls (targetEl) {
fromEvent('mousewheel', targetEl, {passive: false, capture: false}).forEach(preventDefault)
fromEvent('DOMMouseScroll', targetEl, {passive: false, capture: false}).forEach(preventDefault)
fromEvent('wheel', targetEl, {passive: false, capture: false}).forEach(preventDefault)
fromEvent('touchmove', targetEl, {passive: false, capture: false}).forEach(preventDefault)
}
if (preventScroll) {
preventAllScrolls(targetEl, {passive: passiveEventsHandlers, capture: false})
}
if (preventMenu) {
rightClicks$.forEach(preventDefault)
}
const wheel$ = merge(
fromEvent('wheel', targetEl, {passive: passiveEventsHandlers, capture: false}),
fromEvent('DOMMouseScroll', targetEl, {passive: passiveEventsHandlers, capture: false}),
fromEvent('mousewheel', targetEl, {passive: passiveEventsHandlers, capture: false})
).map(normalizeWheel)
return {
mouseDowns$,
mouseUps$,
mouseMoves$,
rightClicks$,
wheel$,
touchStarts$,
touchMoves$,
touchEnds$,