How to use the vendors/framework.derive function in vendors

To help you get started, we’ve selected a few vendors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ivan-kleshnin / unredux / examples / 8.ddl / client / post-index7 / index.js View on Github external
)(
    // 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$,
github ivan-kleshnin / unredux / examples / 8.ddl / client / post-index7 / index.js View on Github external
}

  // 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),
  ])
github ivan-kleshnin / unredux / examples / 8.ddl / client / post-index7 / index.js View on Github external
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$,
    },
github ivan-kleshnin / unredux / examples / 8.ddl / client / post-index / index.js View on Github external
)(
    // 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$,
github ivan-kleshnin / unredux / examples / 7.1.crud / client / post-detail / index.js View on Github external
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)
github ivan-kleshnin / unredux / examples / 7.2.crud-ssr / client / index.js View on Github external
}

// 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() })
github ivan-kleshnin / unredux / examples / 7.1.crud / client / home / index.js View on Github external
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")
github ivan-kleshnin / unredux / examples / 8.ddl / client / post-detail / index.js View on Github external
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(
github ivan-kleshnin / unredux / examples / 7.1.crud / client / post-edit / index.js View on Github external
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),
github ivan-kleshnin / unredux / examples / 7.2.crud-ssr / client / post-edit / index.js View on Github external
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),