jamesmcnamara / shades

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

chaining multiple modifications #25

Closed oluckyman closed 5 years ago

oluckyman commented 5 years ago

Now, when I need to do multiple modifications on a complex object, I do this:

    let newStore = store;
    newStore = mod('model', 'contours')(push(newContour))(newStore);
    newStore = set('model', 'selection')(newContour)(newStore);
    newStore = set('dragState', 'selectionBefore')(newContour)(newStore);
    newStore = set('dragState', 'selectionAnchor')(point)(newStore);
    newStore = set('activeTool')(null)(newStore);
    newStore = set('mode')(activeTool.initialMode || modes.SCALE)(newStore);
    return newStore;

Just realized, that I can use flow from lodash:

    return _.flow(
      mod('model', 'contours')(push(newContour)),
      set('model', 'selection')(newContour),
      set('dragState', 'selectionBefore')(newContour),
      set('dragState', 'selectionAnchor')(point),
      set('activeTool')(null),
      set('mode')(activeTool.initialMode || modes.SCALE),
    )(store);

Not sure if it's in the scope of that lib to have its own flow analog. If not, it's ok too.

Thanks for your efforts!

jamesmcnamara commented 5 years ago

It just so happens that we do: updateAll

However, by and large this library is supposed to work WITH lodash/fp, not replace it. If you can find an elegant way to do something with lodash/fp or normal lodash, then go for it!