Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[feature] user_context: Extended to allow creation of contexts with c…

…ustom key
  • Loading branch information...
commit 314b31bffdc032e4b8e4bf173a52d5797b0f1a82 1 parent 9cc4918
Nicolas Glondu authored
Showing with 10 additions and 6 deletions.
  1. +10 −6 stdlib/core/web/context/user_context.opa
16 stdlib/core/web/context/user_context.opa
View
@@ -91,7 +91,7 @@ UserContext =
* @return A UserContext
*/
@server
- make(default : 'state) =
+ make_generic(get_key: -> option(string), default : 'state) =
init = (UserContextMap.empty: stringmap(UserContext.private.t('state)),default)
rec val ctx = Cell.make(init, aux): UserContext.t('state)
and aux2(state,msg) = match msg with
@@ -107,11 +107,7 @@ UserContext =
match UserContextMap.get(client, state) with
| {some=c} -> (c,false)
| {none} -> (Cell.make(default,aux2),true)
- client = match thread_context().key with
- | {nothing} | {server=_server} ->
- do Log.warning("UserContext","Cannot identify user. This execution is not attached to any user")
- ""
- | {~client} -> client.client
+ client = get_key() ? error("Boum")
match msg with
| {~exec} ->
(c,new) = get_info(client, state)
@@ -137,6 +133,14 @@ UserContext =
instruction={set=(state,set_default)}}
ctx
+ make(default:'state) =
+ client() = match thread_context().key with
+ | {nothing} | {server=_server} ->
+ do Log.warning("UserContext","Cannot identify user. This execution is not attached to any user")
+ none
+ | {~client} -> some(client.client)
+ make_generic(client, default)
+
/**
* [change(f, context)] Change the state of a UserContext
*
Please sign in to comment.
Something went wrong with that request. Please try again.