Skip to content

Allow to skip spread updates with special token #328

@zerobias

Description

@zerobias

One of key features of spread is an ability to skip updates for some targets, but it requires object mutation or weird conditionals (it becomes worse when amount of targets grows):

sample({
  clock: trigger,
  fn: upd => upd.both
    ? ({foo: 0, bar: 0})
    : ({foo: 0})
  target: spread({
    foo,
    bar,
  })
})

// or

sample({
  clock: trigger,
  fn(upd) {
    const result = {foo: 0}
    if (upd.both) {
      result.bar = 0
    }
    return result
  },
  target: spread({
    foo,
    bar,
  })
})

We can add special token SKIP which will mean that this unit will not be triggered:

import {spread, SKIP} from 'patronum'

// or maybe spread.SKIP

sample({
  clock: trigger,
  fn: upd =>({
    foo: 0,
    bar: upd.both ? 0 : SKIP
  }),
  target: spread({
    foo,
    bar,
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCSome new feature that should be discussed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions