drcmda / immer-wieder

✨ React 16 context wrap with redux semantics powered by immer
MIT License
166 stars 9 forks source link

Seeking ideas for implementing history #1

Closed kfrp closed 6 years ago

kfrp commented 6 years ago

Hi, thanks for the great lib, I'm really enjoying working with it so far.

I'm wondering if you have any suggestions for how I can implement history in my store. I'm struggling to grasp it because the store is only accessible as a draft inside setState, which is always going to be mutated, so as far as I can understand I can only ever do something like draft.history.push( draft ) or draft.history.push( draft.someProp ) within some existing action. Would that make sense? And then could I later even revert to it doing draft = draft.history.pop() or something along those lines?

I haven't really interacted directly with immer (only learned about it through your lib), but obviously draft is not a POJO. Should I look there? Is Middleware the right usecase for this? I'm really not sure...

Anyway I'm going to start trying various approaches and I'd greatly appreciate any insights you can provide to be able to wrap my head around this. Thanks!

kfrp commented 6 years ago

Actually I found lots of ideas on the immer page (applyPatches does exactly what I need). I opened this a bit prematurely I think, hence closing.