session icon indicating copy to clipboard operation
session copied to clipboard

use proxies for session data

Open Fishrock123 opened this issue 11 years ago • 17 comments

So that we can check that the store actually exists (#4) and whatever else we want.

req.session.set('thing.property', stuff)

req,session.get('thing.property')

Would be removed of favour of Proxies, eventually. In like a decade when they actually land.

A big issue would be people being idiots and assigning stuff onto the data object or get()-ed objects.

Fishrock123 avatar May 29 '14 23:05 Fishrock123

Meh I would just wait for proxies. This isn't really intuitive

jonathanong avatar May 30 '14 14:05 jonathanong

Citating the example in README.md, you can add user-specific properties in this way

var sess = req.session;
if (sess.views) {
    sess.views++;
} else {
  sess.views = 1;
}

you can even store nested objects

MichaelCereda avatar May 31 '14 14:05 MichaelCereda

@MichaelCereda This a feature proposal, not a question. ;)

Fishrock123 avatar May 31 '14 16:05 Fishrock123

Yes, I know that, but I'm guessing why it should be necessary? you can already interact with session using getter/setter.

MichaelCereda avatar May 31 '14 20:05 MichaelCereda

@MichaelCereda to know if the session was modified to write it back to the store.

dougwilson avatar May 31 '14 20:05 dougwilson

ok so you need to fire an event when session "data" is changed...isn't it?

MichaelCereda avatar Jun 01 '14 04:06 MichaelCereda

In order to implement this, we would probably need to have it on a different property of req in order to not change the way it works currently. If someone wants to do something like this they may be better off looking into another library.

BUT, if it were a configuration option like asStore: true and completely change the behaviour of the req.session object, then it would be okay and non-breaking. Then again all that extra code for event firing and storing might increase the code-base by more than twice LoC, so we might as well have a different version that behaves like that.

colelawrence avatar Jun 01 '14 05:06 colelawrence

@ZombieHippie this would just be a major version bump, i.e. breaking. Also, there is no event firing here, it's just keeping a dirty flag.

dougwilson avatar Jun 01 '14 05:06 dougwilson

this would just be a major version bump, i.e. breaking

@dougwilson I think you are right.

colelawrence avatar Jun 01 '14 05:06 colelawrence

Yes, a major release will be a good thing and allows to implement other breaking feature requests.

MichaelCereda avatar Jun 01 '14 05:06 MichaelCereda

I had already assigned this to a 2.0.0 milestone. :)

Fishrock123 avatar Jun 01 '14 05:06 Fishrock123

i don't think this is worth it unless you allow atomic updates on each .get(). here's how i think sessions are supposed to look like: https://github.com/aheckmann/koa-mongodb-session

jonathanong avatar Jun 17 '14 08:06 jonathanong

Thank you for the example, it should help us understand your suggestions. On Jun 17, 2014 3:01 AM, "Jonathan Ong" [email protected] wrote:

i don't think this is worth it unless you allow atomic updates on each .get(). here's what i think is how sessions are supposed to look like: https://github.com/aheckmann/koa-mongodb-session

— Reply to this email directly or view it on GitHub https://github.com/expressjs/session/issues/46#issuecomment-46278035.

colelawrence avatar Jun 17 '14 16:06 colelawrence

Is this still being pursued for 2.0.0? I also don't see a 2.0.0 branch, but there is a milestone. Any timeline?

ilanbiala avatar Dec 02 '14 22:12 ilanbiala

No real idea, sorry. :/

Fishrock123 avatar Dec 02 '14 23:12 Fishrock123

Proxies are in Node v6, so this should actually be possible now.

Fishrock123 avatar May 02 '16 21:05 Fishrock123

I'd love to play with this. Or push a branch that does something interesting and make a PR and discuss it.

aks- avatar Aug 29 '16 05:08 aks-