Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)(
// Init
D.init(seed),
// Form
intents.changeFilterId$.map(x => R.set2(["filters", "id"], x)),
intents.changeFilterTitle$.map(x => R.set2(["filters", "title"], x)),
intents.changeFilterTags$.map(x => R.set2(["filters", "tags"], x)),
intents.changeFilterIsPublished$.map(x => R.set2(["filters", "isPublished"], x)),
intents.changeFilterPublishDateFrom$.map(x => R.set2(["filters", "publishDateFrom"], x)),
intents.changeFilterPublishDateTo$.map(x => R.set2(["filters", "publishDateTo"], x)),
intents.changeSort$.map(x => R.set2("sort", x)),
).$
let indexPosts$ = deriveObj(
{
index: index$.debounce(200),
table: posts$,
},
({index, table}) => {
if (!table) return null
let filterFn = makeFilterFn(index.filters)
let sortFn = makeSortFn(index.sort)
return R.pipe(
R.values,
R.filter(filterFn),
R.sort(sortFn),
)(table)
}
)
export default (sources, {key}) => {
let intents = {
buy$: sources.DOM.fromKey("productIndex").fromKey("buy").listen("click")
.map(ee => ee.element.dataset.val),
}
let index$ = D.run(
() => D.makeStore({assertFn: R.id}),
D.withLog({key}),
)(
D.init(seed),
).$
let products$ = deriveObj(
{
index: index$,
products: sources.state$.map(s => s.products),
},
({index, products}) => {
// Implies the case when all products are preloaded or loaded at once,
// or when a customer can tolerate reordering of upcoming items.
return R.pipe(
R.values,
R.filter(index.filterFn),
R.sort(index.sortFn),
)(products)
}
)
let action$ = K.merge([
)(
D.init(seed),
// Updates
intents.setFilter$.map(filter => function setFilter(state) {
let filterFn = R.id
if (filter == "completed") {
filterFn = isCompleted
} else if (filter == "active") {
filterFn = isActive
}
return R.set2("filterFn", filterFn, state)
}),
).$
let todos$ = deriveObj(
{
index: state$,
todos: sources.state$.map(s => s.todos),
},
({index, todos}) => {
return R.pipe(
R.values,
R.filter(index.filterFn),
R.sort(index.sortFn),
)(todos)
}
)
let action$ = K.merge([
intents.toggleTodo$.map(id => function toggleTodo(state) {
return R.over2(["todos", id, "completed"], R.not, state)
)(
// Init
D.init(seed),
// Form
intents.changeFilterId$.map(x => R.set2(["filters", "id"], x)),
intents.changeFilterTitle$.map(x => R.set2(["filters", "title"], x)),
intents.changeFilterTags$.map(x => R.set2(["filters", "tags"], x)),
intents.changeFilterIsPublished$.map(x => R.set2(["filters", "isPublished"], x)),
intents.changeFilterPublishDateFrom$.map(x => R.set2(["filters", "publishDateFrom"], x)),
intents.changeFilterPublishDateTo$.map(x => R.set2(["filters", "publishDateTo"], x)),
intents.changeSort$.map(x => R.set2("sort", x)),
).$
let indexPosts$ = deriveObj(
{
index: index$.debounce(200),
table: posts$,
},
({index, table}) => {
if (!table) return null
let filterFn = makeFilterFn(index.filters)
let sortFn = makeSortFn(index.sort)
return R.pipe(
R.values,
R.filter(filterFn),
R.sort(sortFn),
)(table)
}
)