cerebral / overmind

Overmind - Frictionless state management
https://overmindjs.org
MIT License
1.58k stars 95 forks source link

Holding objects in state without proxying them #506

Open gsimone opened 3 years ago

gsimone commented 3 years ago

Hey, we are moving a big codebase to overmind and I'm loving it <3 I wanted to ask if there's a way to hold a reference without actually proxying it, since it would be convenient to be able to transport objects around without actually listening to mutations. My temp solution is to have them in an effect.

Valtio - another proxy-based state lib - implemented a ref helper to opt out of proxying, think it would be possible to have something like this? I'd be up for contributing it, if it's something you are interested in adding! Otherwise, pointers as to where I could patch or otherwise add the feature in userland, would be appreciated.

Thank you so much for the awesome lib!

Valtio - https://github.com/pmndrs/valtio#holding-objects-in-state-without-tracking-them

m9dfukc commented 3 years ago

@gsimone did you further invest in this? I also would be interested in such feature!

ssijak commented 3 years ago

My solution to this when I needed it was to store a function which returns that object instead storing the object directly. So: instead

const store = {
  coolItem
}

do

const store = {
    getCoolItem: () => {return coolItem}
}