koa-mongodb-session icon indicating copy to clipboard operation
koa-mongodb-session copied to clipboard

abstract to a generic "thing"

Open jonathanong opened this issue 11 years ago • 4 comments

i'm not sure how to explain it. right now, you're tying some session object to a request. would be nice if you split out the entire session object logic, i.e. all those modifiers, to a module that creates objects with these modifiers.

var obj = store.get(id)
// if obj exists
yield obj.$set('name', 'aaron')
yield obj.$inc('views', 1)

in particular, i'd like to do the following:

var store = require('mongoose-mini') // or whatever you'd like to call it

app.use(function* (next) {
  var sid = this.session.sid // custom sid
  var obj
  if (sid) obj = yield store.get(sid)
  if (!obj) {
    sid = session.sid = uid(12)
    obj = yield store.create(sid) // or something
  }
  this.someArbitraryObject = obj

  yield* next
})

this way, you have both a session store and a database store. hell, you could even use multiple stores per request for whatever reason!

jonathanong avatar Jun 12 '14 07:06 jonathanong

yeah definitely eat to split this up more. this is a first pass. want me to add you?

aheckmann avatar Jun 12 '14 15:06 aheckmann

s/eat/want haha

aheckmann avatar Jun 12 '14 15:06 aheckmann

added you

aheckmann avatar Jun 12 '14 15:06 aheckmann

won't work on this anytime soon since i don't actually need it. just a thought :D

jonathanong avatar Jun 13 '14 00:06 jonathanong