mobx-stored icon indicating copy to clipboard operation
mobx-stored copied to clipboard

Use with Maps and Sets

Open bsbechtel opened this issue 8 years ago • 10 comments
trafficstars

Can this library be used with JavaScript Maps and Sets? I'm not having any luck adding values to a Set used in the store.

bsbechtel avatar Mar 02 '17 14:03 bsbechtel

+1 this question

johndevor avatar Mar 17 '17 16:03 johndevor

oh yeah, it won't work. I will add support for them in milestones 0.9.6. Will have to store a type information somewhere but that should not be that hard.

capaj avatar Mar 17 '17 18:03 capaj

I'm trying to put together something for this...

johndevor avatar Mar 29 '17 20:03 johndevor

Dumb question, but when you're referring to "Sets" in javascript, you're talking about associative arrays, correct?

johndevor avatar Mar 30 '17 14:03 johndevor

Also, what do you guys think of a method signature like this?

function storedObservable (key, defaultValue, debounce = 500, type)

johndevor avatar Mar 30 '17 15:03 johndevor

@johndevor that's a good question. We should definitely support a Map because MobX has it's observable counterpart implemented already. When it comes to Sets, I am no really sure.

In regards to the the type- we can easily recognize it from the default value so there's no need for programmer to hint the type via en extra parameter.

capaj avatar Mar 30 '17 15:03 capaj

How do you recognize the difference between an obj and a map in these cases?

storedObservable('text', {'myObjKey':1}, 500)

storedObservable('text', {'myMapKey':1}, 500)

Both of the default values appear to be similar objects to me. Unless you had in mind changing the method signature entirely to something like:

storedMapObservable

johndevor avatar Mar 30 '17 15:03 johndevor

@johndevor I was thinking more like:

const defaultMap = new Map()
defaultMap.set('myMapKey', 1)
storedObservable('text', defaultMap, 500)

capaj avatar Mar 30 '17 15:03 capaj

Ah yes of course. 👍

On Thu, Mar 30, 2017, 11:35 AM Jiri Spac [email protected] wrote:

@johndevor https://github.com/johndevor I was thinking more like:

const defaultMap = new Map()defaultMap.set('myMapKey', 1)storedObservable('text', defaultMap, 500)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/capaj/mobx-stored/issues/1#issuecomment-290449614, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEoM5vEsbRl0UlxtRnZTvoEumOWGOKhks5rq8vXgaJpZM4MRBw0 .

johndevor avatar Mar 30 '17 17:03 johndevor

Haven't had time to get to this if anybody wants to take a stab at it...

johndevor avatar Apr 19 '17 20:04 johndevor