Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}),
navigateHistory$: D.isBrowser
? K.fromEvents(window, "popstate")
.map(data => {
let urlObj = U.parse(document.location.href)
// Browser recovers scroll position at popstate
return urlObj.relHref
})
: K.never()
}
let urlPool$ = poolProp(props.url)
let route$ = K
.merge([
urlPool$,
intents.navigateTo$,
intents.navigateHistory$,
])
.skipDuplicates(U.equals)
.flatMapLatest(url => {
if (D.isBrowser) {
window.history.pushState({}, "", url)
}
let routeResult = router.doroute(url)
return K.fromPromise(routeResult.payload().then(app => {
return {...routeResult, app, url}
}))
})
.map(({mask, params, app, url}) => {
let deriveState = derive(sources.state$.throttle(50))
let post$ = deriveState(baseLens)
let loading$ = deriveState(loadingLens).map(Boolean)
// COMPONENT
let Component = connect(
{
post: post$,
loading: loading$,
},
PostDetail
)
// ACTIONS
let action$ = K.merge([
post$
.filter(R.not)
.flatMapConcat(_ => K.stream(async (emitter) => {
emitter.value(function fetchStarted(state) {
return incLoading(state)
})
let reqResult = await fetchJSON(`/api/${baseLens.join("/")}/`)
if (reqResult instanceof Error) {
console.warn(reqResult.message)
emitter.value(function fetchFailed(state) {
// + Set your custom alerts here
return decLoading(state)
})
} else {
let post = reqResult.models[params.id]
)(table)
}
)
// COMPONENT
let Component = connect(
{
index: index$,
posts: indexPosts$,
loading: loading$,
},
PostIndex
)
// ACTIONS
let action$ = K.merge([
posts$
.filter(posts => {
// Use local `offset` and `limit` here to detect missing posts
return !posts || R.keys(posts).length < 12
})
.flatMapConcat(posts => K.stream(async (emitter) => {
// We intentionally use special loading strategy here to demonstrate how 2+ requests will
// interoperate. Check 8.dll example for more conventional fetching and caching approach.
// Here we always fetch ids and then models if necessary.
emitter.value(function fetchStarted(state) {
return incLoading(state)
})
let reqResult = await fetchJSON(`/api/posts/~/id/`)
if (reqResult instanceof Error) {
console.warn(reqResult.message)
const createTinyMCEButton = (actions$: Observable, state$: Observable, editor: Editor): Observable =>Kefir.merge([
Kefir.stream((emitter: Emitter) => {
// Bind command to stream.
editor.addCommand('wpgp_insert', () => void emitter.value(tinymceButtonClick()));
// Add the Insert Gistpen button
editor.addButton('wp_gistpen', {
icon: 'icons dashicons-editor-code',
tooltip: 'Insert Gistpen',
cmd: 'wpgp_insert'
});
}),
state$.sampledBy(actions$.thru(ofType(tinymcePopupInsertClick)))
.flatMap((state: TinyMCEState) => Kefir.stream((emitter: Emitter) => {
if (state.search.selection != null) {
editor.insertContent('[gistpen id="' + state.search.selection + '"]');
}
.add('kefir', function(deferred) {
const streams = a.map(kefirFromArray);
runners.runKefir(deferred, kefir.merge(streams).scan(sum, 0).last());
}, options)
.add('bacon', function(deferred) {
export default (sources, {key, title}) => {
let intents = {
inc$: sources.DOM.fromKey("inc").listen("click").map(R.always(true)),
dec$: sources.DOM.fromKey("dec").listen("click").map(R.always(true)),
}
let action$ = K.merge([
intents.inc$.map(_ => R.inc),
intents.dec$.map(_ => R.dec),
])
let Component = connect(
{counter: sources.state$},
({counter}) =>
<p>
{title}: <span>{counter}</span>
{" "}
<button data-key="inc">+1</button>
{" "}
<button data-key="dec">-1</button>
</p>
)
export default R.curry((services, actions$, state$) =>
Kefir.merge([
log(services, actions$, state$),
state$.sampledBy(actions$.thru(ofType(RUN))).take(1).flatMap(state => {
switch (state.command.name) {
case 'new':
return newCommandPrompt(services, actions$, state$);
case 'dev':
return devCommand(services, actions$, state$);
case 'make':
case 'test':
case 'build':
return Kefir.never();
default:
return commandNotFound(services, actions$, state$);
}
})
]));
.add('kefir', function(deferred) {
var streams = a.map(kefirFromArray);
runners.runKefir(deferred, kefir.merge(streams).scan(sum, 0).last());
}, options)
.add('bacon', function(deferred) {
search = parseQueryString(search);
}
if (search[param]) {
emitter.value(router(`/${search[param]}`));
} else {
location.href = href;
emitter.end();
}
};
href(emit);
hist(emit);
});
return Kefir.merge([initial$, pushState$, href$]);
};
sources.map(src => {
let filesToCopy;
if (watch) {
const chokidar = require('chokidar');
const watcher = chokidar.watch(jsAndJsxPattern, {cwd: src, ignored: ignore});
filesToCopy = Kefir.merge([
Kefir.fromEvents(watcher, 'add'),
Kefir.fromEvents(watcher, 'change')
]);
} else {
filesToCopy = kefirGlob(jsAndJsxPattern, {cwd: src, strict: true, ignore});
}
return filesToCopy.map(match => ({src, match}));
})
)