koa-mongodb-session
koa-mongodb-session copied to clipboard
abstract to a generic "thing"
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!
yeah definitely eat to split this up more. this is a first pass. want me to add you?
s/eat/want haha
added you
won't work on this anytime soon since i don't actually need it. just a thought :D