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),
intents.loadNext$.map(_ => s => R.over2("offset", R.add(s.limit), s))
).$
// DATA & LOAD
let deriveState = derive(sources.state$.throttle(50))
let loading$ = deriveState("loading")
let indexes$ = deriveState("indexes")
let postsTable$ = deriveState(["tables", "7/posts"])
let usersTable$ = deriveState(["tables", "7/users"])
let index$ = deriveLazyLoad(indexes$, localIndex$, postIndexQuery) // :: $ (Array String)
let postIds$ = derive(index$, "ids") // :: $ (Array String)
let posts$ = deriveModelsArr(postsTable$, postIds$, validate(Post)) // :: $ (Array Post)
let userIds$ = derive(posts$, R.pipe(R.pluck("userId"), R.uniq)) // :: $ (Array String)
let users$ = deriveModelsObj(usersTable$, userIds$, validate(User)) // :: $ (Object User)
let load$ = K.merge([
index$.map(postIndexQuery),
postIds$.map(postModelsQuery),
userIds$.map(userModelsQuery),
])
// COMPONENT
let Component = connect(
{
loading: loading$,
index: index$,
posts: posts$,
}
// STATE
let localIndex$ = D.run(
() => D.makeStore({}),
// D.withLog({key, input: false, output: true}),
D.withMemoryPersistence({key: "7." + key}),
)(
// Init
D.init(seed),
intents.loadNext$.map(_ => s => R.over2("offset", R.add(s.limit), s))
).$
// DATA & LOAD
let deriveState = derive(sources.state$.throttle(50))
let loading$ = deriveState("loading")
let indexes$ = deriveState("indexes")
let postsTable$ = deriveState(["tables", "7/posts"])
let usersTable$ = deriveState(["tables", "7/users"])
let index$ = deriveLazyLoad(indexes$, localIndex$, postIndexQuery) // :: $ (Array String)
let postIds$ = derive(index$, "ids") // :: $ (Array String)
let posts$ = deriveModelsArr(postsTable$, postIds$, validate(Post)) // :: $ (Array Post)
let userIds$ = derive(posts$, R.pipe(R.pluck("userId"), R.uniq)) // :: $ (Array String)
let users$ = deriveModelsObj(usersTable$, userIds$, validate(User)) // :: $ (Object User)
let load$ = K.merge([
index$.map(postIndexQuery),
postIds$.map(postModelsQuery),
userIds$.map(userModelsQuery),
])
D.init(seed),
intents.loadNext$.map(_ => s => R.over2("offset", R.add(s.limit), s))
).$
// DATA & LOAD
let deriveState = derive(sources.state$.throttle(50))
let loading$ = deriveState("loading")
let indexes$ = deriveState("indexes")
let postsTable$ = deriveState(["tables", "7/posts"])
let usersTable$ = deriveState(["tables", "7/users"])
let index$ = deriveLazyLoad(indexes$, localIndex$, postIndexQuery) // :: $ (Array String)
let postIds$ = derive(index$, "ids") // :: $ (Array String)
let posts$ = deriveModelsArr(postsTable$, postIds$, validate(Post)) // :: $ (Array Post)
let userIds$ = derive(posts$, R.pipe(R.pluck("userId"), R.uniq)) // :: $ (Array String)
let users$ = deriveModelsObj(usersTable$, userIds$, validate(User)) // :: $ (Object User)
let load$ = K.merge([
index$.map(postIndexQuery),
postIds$.map(postModelsQuery),
userIds$.map(userModelsQuery),
])
// COMPONENT
let Component = connect(
{
loading: loading$,
index: index$,
posts: posts$,
users: users$,
},
)(
// Init
D.init(seed),
intents.loadNext$.map(_ => s => R.over2("offset", R.add(s.limit), s))
).$
// DATA & LOAD
let deriveState = derive(sources.state$.throttle(50))
let loading$ = deriveState("loading")
let indexes$ = deriveState("indexes")
let postsTable$ = deriveState(["tables", `${params.subset}/posts`])
let usersTable$ = deriveState(["tables", `${params.subset}/users`])
let index$ = deriveLazyLoad(indexes$, localIndex$, postIndexQuery) // :: $ (Array String)
let postIds$ = derive(index$, "ids") // :: $ (Array String)
let posts$ = deriveModelsArr(postsTable$, postIds$, validate(Post)) // :: $ (Array Post)
let userIds$ = derive(posts$, R.pipe(R.pluck("userId"), R.uniq)) // :: $ (Array String)
let users$ = deriveModelsObj(usersTable$, userIds$, validate(User)) // :: $ (Object User)
let load$ = K.merge([
index$.map(postIndexQuery),
postIds$.map(postModelsQuery),
userIds$.map(userModelsQuery),
])
// COMPONENT
let Component = connect(
{
loading: loading$,
index: index$,
posts: posts$,
export default (sources, {key, params}) => {
let baseLens = ["posts", params.id]
let loadingLens = "loading"
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)
}
// Prepare props
let props = {
key: APP_KEY,
url: document.location.href.replace(document.location.origin, ""),
}
// Run app to get sinks
let sinks = app(sources, props)
// Cycle the root state
sinks.state$.observe(sources.state$.plug)
// Side-effects
K.combine([sinks.route$], [derive(sinks.state$, "document")]).observe(([route, doc]) => {
document.title = doc.title
// Other possibilities:
// descriptionElem.setAttribute("content", doc.description || "")
// ogTitleElem.setAttribute("content", doc.title || "")
// ogTypeElem.setAttribute("content", doc.ogType || "")
// ogUrlElem.setAttribute("content", document.location.origin + route.url)
// ogImageElem.setAttribute("content", doc.ogImage ? document.location.origin + doc.ogImage : "")
// ogDescriptionElem.setAttribute("content", doc.description || "")
// if (window.ga) {
// window.ga("set", "page", route.url)
// window.ga("send", "pageview")
// }
})
sinks.effect$.observe(fn => { fn() })
export default (sources, {key, params}) => {
let baseLens = ["posts"]
let loadingLens = "loading"
let deriveState = derive(sources.state$.throttle(50))
let posts$ = deriveState(baseLens)
let loading$ = deriveState(loadingLens).map(Boolean)
// INTENTS
let intents = {
// DOM
changeFilterId$: sources.DOM.fromName("filters.id").listen("input")
.map(ee => ee.element.value),
changeFilterTitle$: sources.DOM.fromName("filters.title").listen("input")
.map(ee => ee.element.value),
changeFilterTags$: sources.DOM.fromName("filters.tags").listen("input")
.map(ee => ee.element.value),
changeFilterIsPublished$: sources.DOM.fromName("filters.isPublished").listen("click")
export default (sources, {key, params}) => {
// --- Testing scenarios ---
let {Post, User, postModelQuery, userModelQuery} = makeScenarios(params.subset)
// ---
// DATA & LOAD
let deriveState = derive(sources.state$.throttle(50))
let loading$ = deriveState("loading")
let postsTable$ = deriveState(["tables", `${params.subset}/posts`]) // TODO disable R.equals check
let usersTable$ = deriveState(["tables", `${params.subset}/users`]) // in kefir.db – too expensive?
let postId$ = K.constant(params.id) // :: $ String
let post$ = deriveModel(postsTable$, postId$, validate(Post)) // :: $ (Post | null)
let userId$ = derive(post$, R.prop("userId")) // :: $ String
let user$ = deriveModel(usersTable$, userId$, validate(User)) // :: $ (User | null)
let load$ = K.merge([
postId$.map(postModelQuery),
userId$.map(userModelQuery),
])
// COMPONENT
let Component = connect(
export default (sources, {key, params}) => {
let baseLens = ["posts", params.id]
let deriveState = derive(sources.state$.throttle(50))
let post$ = deriveState(baseLens)
// INTENTS
let intents = {
changeTitle$: sources.DOM.fromName("title").listen("input")
.map(ee => ee.element.value),
changeText$: sources.DOM.fromName("text").listen("input")
.map(ee => ee.element.value),
changeTags$: sources.DOM.fromName("tags").listen("input")
.map(ee => ee.element.value),
changeIsPublished$: sources.DOM.fromName("isPublished").listen("click")
.map(ee => ee.element.checked),
export default (sources, {key, params}) => {
let baseLens = ["posts", params.id]
let deriveState = derive(sources.state$.throttle(50))
let post$ = deriveState(baseLens)
// INTENTS
let intents = {
changeTitle$: sources.DOM.fromName("title").listen("input")
.map(ee => ee.element.value),
changeText$: sources.DOM.fromName("text").listen("input")
.map(ee => ee.element.value),
changeTags$: sources.DOM.fromName("tags").listen("input")
.map(ee => ee.element.value),
changeIsPublished$: sources.DOM.fromName("isPublished").listen("click")
.map(ee => ee.element.checked),