101 icon indicating copy to clipboard operation
101 copied to clipboard

"Push" method

Open srph opened this issue 7 years ago • 2 comments

Maybe we could have an immutable push (and unshift?) method.

Before

return put(state, 'data', [
  ...state.data,
  action.payload
])

After

return push(state, 'data', action.payload)

I've been using 101 recently in my newer projects, and I've been meaning to have something like this.

Not sure if it's "bloat", but let me know what you think. I can send a PR if you think this sounds good.

srph avatar Apr 13 '17 09:04 srph

I was thinking of creating an invoke method that may satisfy your needs:

invoke(state, 'data.push', action.payload)

Although that would not me an immutable helper. We may be able to create an immutable invoke as well. I've been wanting to reorganize 101 into pairs of helper (immutable and not).

Let me know your thoughts

tjmehta avatar Apr 16 '17 22:04 tjmehta

invoke sounds cool. I'm not sure how to name it, but I presume that people won't use both immutable and mutable invoke at the same time, so maybe we could do:

// Mutable
const invoke = require('101/invoke')
// Immutable
const invoke = require('101/invoke-immutable')

srph avatar Apr 25 '17 01:04 srph