How to use the vendors/framework.deriveObj 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 / 7.2.crud-ssr / client / home / index.js View on Github external
)(
    // 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)
    }
  )
github ivan-kleshnin / unredux / examples / 6.shopping-cart / src / product-index / index.js View on Github external
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([
github ivan-kleshnin / unredux / examples / 4.todos / src / todo-index / index.js View on Github external
)(
    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)
github ivan-kleshnin / unredux / examples / 7.1.crud / client / home / index.js View on Github external
)(
    // 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)
    }
  )