abc icon indicating copy to clipboard operation
abc copied to clipboard

Session improvements

Open LarsVomMars opened this issue 4 years ago • 6 comments

  • [x] Skipper
  • [x] Tests
  • [ ] Better typings
  • [ ] Session field

Better typings

I already considered this but IMO it's very useful to be able to store data of any kind/type in a session variable without being limited to some basic types. You probably could serialize the data into JSON on the store side which would get rid of 3 any typings.

Session field

Well I first thought of using a CustomContext for that but this would only complicate things because the user would have to instantiate the CC on every request he wants to access the session data.

~ Lars

LarsVomMars avatar Aug 03 '20 07:08 LarsVomMars

Thanks @marvinborner for the tests :)

LarsVomMars avatar Aug 05 '20 10:08 LarsVomMars

I think we should discuss the last two points on the list because so far I see this, there is not really a better solution to them.

LarsVomMars avatar Aug 05 '20 22:08 LarsVomMars

Below is my design:

// session.ts
export const key = Symbol("abc.session")
interface SessionConfig {
  skipper: ...
  // required
  store: ...
}

// this func create a session mw
export function mw(cfg) {}

export function get(name: string, c: Context): Session {
  // const s = c.get(key)
  // return s.get(name)
}

// main.ts
import * as session from "./session.ts"

app.use(session.mw({...}))

app.get("/", c => {
  sess = session.get("session", c)
  // Then, we need a way to set the session options, such as maxAge, etc.
})

zhmushan avatar Aug 06 '20 10:08 zhmushan

Although I don't see how this would improve the workflow yet is justifiable for the user in any way. Like I mean in this case I could use a CustomContext as well which would lead to a better/more usable version in the end.

-- Didn't see the lastest commit, will look into it later.

LarsVomMars avatar Aug 06 '20 22:08 LarsVomMars

@LarsVomMars Sorry for late, thanks for your contribution. If you agree, I will make improvements directly on your branch, probably next week

zhmushan avatar Aug 12 '20 15:08 zhmushan

You free to edit. I can't do this much atm, because my attention is currently drawn to some other projects.

LarsVomMars avatar Aug 12 '20 15:08 LarsVomMars