jamesmcnamara / shades

A lodash-inspired lens-like library for Javascript
MIT License
412 stars 14 forks source link

Conditional and branching ? #34

Closed wcastand closed 4 years ago

wcastand commented 4 years ago

Hi, first of all, really nice lib :)

i run into an issue i didn't know how to solve with shades.

i want to udpate my state but i need branching/conditions i received an array: if the array contain my new element already then update that element otherwise add the element as a new one.

Right now this is what i have(drop function):

    {
  const [{ item }, drop] = useDrop<Item, void, { item: Item }>({
    canDrop: checkCanDrop,
    accept: Object.keys(configItems),
    drop: y =>
      setState(
        s.mod('selected')(selected =>
          s.some({ customerType: y.customerType, type: y.type })(selected)
            ? s.mod(s.matching({ customerType: y.customerType, type: y.type }))(
                (x: Item) => ({ ...x, customerType, level, isLock: false, isDropped: true } as Item),
              )(selected)
            : s.cons({ ...y, isDropped: true, isLock: false, level, customerType } as Item)(selected),
        ),
      ),
    collect: monitor => ({ item: monitor.getItem() }),
  })

Thank for the help and sorry if that wasn't the right place to ask :/

PS: also since i made an issue, i can see that there is no update in 6 month, is this library still worked on or reached a stable level or unmaintained? :)

jamesmcnamara commented 4 years ago

Yeah, your approach seems fine. There aren't any shortcut functions to do that; it's a pretty custom piece of logic.

I do still keep an eye on it. It's stable and I use it in production everyday, but I can be pretty slow on resolving issues that come up.