Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).flatMapErrors(err => {
console.warn(`Request to "${err.response.config.url}" failed with message "${err.response.status} ${err.response.statusText}"`)
return K.never() // TODO add alert box
})
])
// INTENTS
let intents = {
navigateTo$: sources.DOM.from("a").listen("click")
.map(ee => (ee.event.preventDefault(), ee))
.map(ee => ee.element.href)
.map(url => {
url = Url.parse(url).pathname
window.history.pushState({}, "", url)
return url
}),
navigateHistory$: D.isBrowser
? K.fromEvents(window, "popstate")
.map(data => document.location.pathname)
: K.never()
}
// STATE
let state$ = D.run(
() => D.makeStore({}),
// D.withLog({key}),
)(
// Init
D.init(seed),
D.initAsync(sources.state$),
// Navigation
intents.navigateTo$.map(url => R.fn("navigateTo", R.set("url", url))),
intents.navigateHistory$.map(url => R.fn("navigateHistory", R.set("url", url))),
// Content
.flatMapConcat(ee => {
let urlObj = U.parse(ee.element.href)
if (urlObj.protocol && urlObj.host != document.location.host) {
// External link
return K.never()
}
else if (ee.event.shiftKey || navigator.platform.match("Mac") ? ee.event.metaKey : ee.event.ctrlKey) {
// Holding Shift or Ctrl/Cmd
return K.never()
}
else {
// Internal link
if (urlObj.pathname == document.location.pathname && urlObj.hash) {
// Anchor link
// do nothing, rely on default browser behavior
} else {
// Page link or Reset-Anchor link (foo#hash -> foo)
ee.event.preventDefault() // take control of browser
window.scrollTo(0, 0) //
}
window.history.pushState({}, "", urlObj.relHref)
return K.constant(urlObj.relHref)
}
}),
// Anchor link
// do nothing, rely on default browser behavior
} else {
// Page link or Reset-Anchor link (foo#hash -> foo)
ee.event.preventDefault() // take control on browser
window.scrollTo(0, 0) //
}
window.history.pushState({}, "", urlObj.relHref)
return K.constant(urlObj.relHref)
}
}),
navigateHistory$: D.isBrowser
? K.fromEvents(window, "popstate")
.map(data => U.relHref(document.location.href)) // TODO scroll to hash (how?!)
: K.never(),
}
}
expect(loop(() => Kefir.never())).to.be.a('function');
});
action$: page$.flatMapLatest(p => p.action$ || K.never()),
.map(url => {
let {mask, params, payload: app} = router.doroute(url)
app = isolate(app, key + mask, ["DOM", "Component"])
let sinks = app({...sources, props: {mask, params, router}})
return R.merge({action$: K.never()}, sinks)
})
const error$ = actions$.flatMap(({ type, payload }) => {
switch (type) {
case SCAFFOLD_ERROR:
return Kefir.concat([
ui.error(`error scaffolding file: ${payload.error.message}`),
setExitCode(1)
]);
case READ_RC_FILE_ERROR:
return Kefir.concat([
ui.error(`error reading .beaverrc.js: ${payload.error.message}`),
setExitCode(1)
]);
default:
return Kefir.never();
}
});
var delay = /*#__PURE__*/I.curry(function delay(ms, xs) {
if (isObservable(xs)) return xs.delay(ms);else return xs;
});
var mapValue = /*#__PURE__*/I.curry(mapValueU);
var flatMapParallel = /*#__PURE__*/I.curry(flatMapParallelU);
var flatMapSerial = /*#__PURE__*/I.curry(flatMapSerialU);
var flatMapErrors = /*#__PURE__*/I.curry(function flatMapErrors(fn, xs) {
return toObservable(xs).flatMapErrors(I.pipe2U(fn, toObservable));
});
var flatMapLatest = /*#__PURE__*/I.curry(flatMapLatestU);
var foldPast = /*#__PURE__*/I.curry(function foldPast(fn, s, xs) {
if (isObservable(xs)) return xs.scan(fn, s);else return fn(s, xs);
});
var interval = /*#__PURE__*/I.curry(K.interval);
var later = /*#__PURE__*/I.curry(K.later);
var never = /*#__PURE__*/K.never();
var on = /*#__PURE__*/I.curry(function on(efs, xs) {
return toObservable(xs).onAny(toHandler(efs));
});
var sampledBy = /*#__PURE__*/I.curry(function sampledBy(es, xs) {
return toObservable(xs).sampledBy(es);
});
var skipFirst = /*#__PURE__*/I.curry(function skipFirst(n, xs) {
return toObservable(xs).skip(n);
});
var skipDuplicates = /*#__PURE__*/I.curry(function skipDuplicates(equals, xs) {
if (isObservable(xs)) return xs.skipDuplicates(equals);else return xs;
});
var skipUnless = /*#__PURE__*/I.curry(function skipUnless(p, xs) {
return toObservable(xs).filter(p);
});
var takeFirst = /*#__PURE__*/I.curry(function takeFirst(n, xs) {
var delay = /*#__PURE__*/curry(function delay(ms, xs) {
if (isObservable(xs)) return xs.delay(ms);else return xs;
});
var mapValue = /*#__PURE__*/curry(mapValueU);
var flatMapParallel = /*#__PURE__*/curry(flatMapParallelU);
var flatMapSerial = /*#__PURE__*/curry(flatMapSerialU);
var flatMapErrors = /*#__PURE__*/curry(function flatMapErrors(fn, xs) {
return toObservable(xs).flatMapErrors(pipe2U(fn, toObservable));
});
var flatMapLatest = /*#__PURE__*/curry(flatMapLatestU);
var foldPast = /*#__PURE__*/curry(function foldPast(fn, s, xs) {
if (isObservable(xs)) return xs.scan(fn, s);else return fn(s, xs);
});
var interval$1 = /*#__PURE__*/curry(interval);
var later$1 = /*#__PURE__*/curry(later);
var never$1 = /*#__PURE__*/never();
var on = /*#__PURE__*/curry(function on(efs, xs) {
return toObservable(xs).onAny(toHandler(efs));
});
var sampledBy = /*#__PURE__*/curry(function sampledBy(es, xs) {
return toObservable(xs).sampledBy(es);
});
var skipFirst = /*#__PURE__*/curry(function skipFirst(n, xs) {
return toObservable(xs).skip(n);
});
var skipDuplicates = /*#__PURE__*/curry(function skipDuplicates(equals, xs) {
if (isObservable(xs)) return xs.skipDuplicates(equals);else return xs;
});
var skipUnless = /*#__PURE__*/curry(function skipUnless(p, xs) {
return toObservable(xs).filter(p);
});
var takeFirst = /*#__PURE__*/curry(function takeFirst(n, xs) {