Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
changeFilterIsPublished$: sources.DOM.fromName("filters.isPublished").listen("click")
.map(ee => ee.element.checked),
changeFilterPublishDateFrom$: sources.DOM.fromName("filters.publishDateFrom").listen("input")
.map(ee => ee.element.value),
changeFilterPublishDateTo$: sources.DOM.fromName("filters.publishDateTo").listen("input")
.map(ee => ee.element.value),
changeSort$: sources.DOM.fromName("sort").listen("click")
.map(ee => ee.element.value),
}
// STATE
let index$ = D.run(
() => D.makeStore({}),
// D.withLog({key}),
)(
// 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)),
).$
export default (sources, {key}) => {
let intents = {
inputText$: sources.DOM.from("input[name=text]").listen("input")
.map(ee => ee.element.value),
submitForm$: sources.DOM.from("form").listen("submit")
.map(ee => (ee.event.preventDefault(), ee))
.map(R.always(true)),
}
let form$ = D.run(
() => D.makeStore({}),
D.withLog({key}),
)(
D.init(seed),
// Updates
intents.inputText$.map(text => function inputText(state) {
return R.set2("text", text, state)
}),
// Resets
intents.submitForm$.delay(1).map(_ => function reset(state) {
return seed
}),
).$
export default (sources, {key}) => {
let intents = {
// unsubscribed on state unsubscribe which happens on willUnmount
inc$: sources.DOM.fromKey("inc").listen("click").map(R.always(true)),
dec$: sources.DOM.fromKey("dec").listen("click").map(R.always(true)),
}
let state$ = D.run(
() => D.makeStore({}),
// D.withLog({key}),
D.withLocalStoragePersistence({key: "3.2.router." + key}),
)(
D.init(0),
intents.inc$.map(_ => R.inc),
intents.dec$.map(_ => R.dec),
).$
let Component = connect(
{counter: state$},
({counter}) =>
<div>
Page 2: {counter} <button data-key="inc">+1</button> <button data-key="dec">-1</button>
<p><i>Local Storage persistence</i></p>
</div>
export default (sources, {key}) => {
let intents = {
toggleTodo$: sources.DOM.fromKey("item").listen("click")
.map(ee => ee.element.dataset.val),
setFilter$: sources.DOM.fromKey("filter").listen("click")
.map(ee => (ee.event.preventDefault(), ee))
.map(ee => ee.element.dataset.val),
}
let state$ = D.run(
() => D.makeStore({assertFn: R.id}),
D.withLog({key}),
)(
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)
}),
).$
.map(s => R.keys(R.view2(baseLens, s)))
.map(R.difference(maybeIds))
.flatMapConcat(missingIds => {
return missingIds.length
? K.fromPromise(
A.get(`/api/${baseLens[0]}/${R.join(",", missingIds)}/`)
.then(resp => resp.data.models)
.catch(R.id)
)
: K.constant({})
})
})
}
// STATE
let index$ = D.run(
() => D.makeStore({}),
// D.withLog({key}),
)(
// Init
D.init(seed),
// Form
intents.changeFilterId$.map(x => R.set2(["filters", "id"], x)),
intents.changeFilterRole$.map(x => R.set2(["filters", "role"], x)),
intents.changeFilterFullname$.map(x => R.set2(["filters", "fullname"], x)),
intents.changeFilterAgeFrom$.map(x => R.set2(["filters", "ageFrom"], x)),
intents.changeFilterAgeTo$.map(x => R.set2(["filters", "ageTo"], x)),
intents.changeSort$.map(x => R.set2("sort", x)),
).$
// Counters A* have their own states, invisible outside
let a1Sinks = isolateDOM(aApp, "a1")(sources, {title: "CounterA1"})
let a2Sinks = isolateDOM(aApp, "a2")(sources, {title: "CounterA2"})
// a*Sinks :: {Component}
// Counters B* have their own states, visible outside
let b1Sinks = isolateDOM(bApp, "b1")(sources, {title: "CounterB1"})
let b2Sinks = isolateDOM(bApp, "b2")(sources, {title: "CounterB2"})
// b*Sinks :: {Component, state$}
// Counters C* use the root state$ and modify it via `action$` sink
let c1Sinks = isolateState(isolateDOM(cApp, "c1"), "c1")(sources, {title: "CounterC1"})
let c2Sinks = isolateState(isolateDOM(cApp, "c2"), "c2")(sources, {title: "CounterC2"})
// c*Sinks :: {Component, action$}
let state$ = D.run(
() => D.makeStore({}),
D.withLog({key}),
)(
D.init(seed),
// Counters A* are irrelevant here
// Counters B* will work without the root state
b1Sinks.state$.skip(1).map(R.set2("b1")),
b2Sinks.state$.skip(1).map(R.set2("b2")),
// Counters C* won't work without the root state
c1Sinks.action$,
c2Sinks.action$,
).$
} else {
let {ids, total} = resp
let models = R.fromPairs(R.zip(ids, R.map(id => ({id}), ids)))
let indexKey = hashIndexQuery(query)
return R.pipe(
R.over2(["tables", tableName], R.mergeDeepFlipped(models)),
R.over2(["indexes", indexKey], R.defaultTo({table: {}, total: 0})),
R.over2(["indexes", indexKey], R.mergeDeepFlipped(makeGlobalIndex(offset, resp))),
R.over2(["loading", tableName], safeDec),
)(state)
}
})
])
// STATE
let state$ = D.run(
() => D.makeStore({}),
// D.withLog({key, input: false, output: true}),
)(
// Init
D.init(seed),
// Page
sources.page$.flatMapLatest(sinks => sinks.action$),
// Load
loadAction$,
).$
// COMPONENT
let Component = connect(
{
let app = (sources, {key}) => {
// STATE
let state$ = D.run(
() => D.makeStore({}),
// D.withLog({key}),
)(
// Init
D.initAsync(sources.state$), // start from serverSeed
// Page
sources.page.action$,
).$
// COMPONENT
let Component = connect(
{
route: sources.route$,
Content: sources.page.Component$,
},
export default (sources, {key}) => {
let intents = {
inc$: sources.DOM.fromKey("inc").listen("click").map(R.always(true)),
dec$: sources.DOM.fromKey("dec").listen("click").map(R.always(true)),
add$: sources.DOM.fromKey("add").listen("click").map(({element}) => Number(element.dataset.val)),
sub$: sources.DOM.fromKey("sub").listen("click").map(({element}) => Number(element.dataset.val)),
}
let state$ = D.run(
() => D.makeStore({}),
D.withLog({key}),
)(
D.init(0),
intents.inc$.map(_ => R.inc),
intents.dec$.map(_ => R.dec),
intents.add$.map(v => R.add(v)),
intents.sub$.map(v => R.flip(R.subtract)(v)),
).$
let Component = connect(
{counter: state$},
({counter}) =>
<p>
Counter: <span>{counter}</span></p>