-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💥 The
Alchemy.ClientSession
class should now be used as a map to st…
…ore session data
- Loading branch information
Showing
4 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,14 +29,14 @@ var LoopConduit = Function.inherits('Alchemy.Conduit', function Loopback(parent_ | |
}); | ||
|
||
/** | ||
* Refer to the parent conduit for the sessionData property | ||
* Refer to the parent conduit for the session_instance property | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.3.10 | ||
* @version 1.3.10 | ||
* @version 1.4.0 | ||
*/ | ||
LoopConduit.setProperty(function sessionData() { | ||
return this.parent.sessionData; | ||
LoopConduit.setProperty(function session_instance() { | ||
return this.parent.session_instance; | ||
}); | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2359,7 +2359,7 @@ Conduit.setMethod(function _sendStream(stream, options) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
* @version 1.3.18 | ||
* @version 1.4.0 | ||
* | ||
* @param {boolean} create Create a session if none exist | ||
* | ||
|
@@ -2368,8 +2368,8 @@ Conduit.setMethod(function _sendStream(stream, options) { | |
Conduit.setMethod(function getSession(allow_create = true) { | ||
|
||
// Only do this once per request | ||
if (this.sessionData != null) { | ||
return this.sessionData; | ||
if (this.session_instance != null) { | ||
return this.session_instance; | ||
} | ||
|
||
let cookie_name = this.session_cookie_name, | ||
|
@@ -2395,7 +2395,7 @@ Conduit.setMethod(function getSession(allow_create = true) { | |
} | ||
|
||
if (session) { | ||
this.sessionData = session; | ||
this.session_instance = session; | ||
session.request_count++; | ||
} else { | ||
return false; | ||
|
@@ -2468,7 +2468,7 @@ Conduit.setMethod(function registerBindings(arr) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
* @version 0.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {string} name | ||
* @param {Mixed} value | ||
|
@@ -2477,17 +2477,17 @@ Conduit.setMethod(function registerBindings(arr) { | |
*/ | ||
Conduit.setMethod(function session(name, value) { | ||
|
||
this.getSession(); | ||
const session = this.getSession(); | ||
|
||
if (arguments.length === 0) { | ||
return this.sessionData; | ||
return session; | ||
} | ||
|
||
if (arguments.length === 1) { | ||
return this.sessionData[name]; | ||
return session.get(name); | ||
} | ||
|
||
this.sessionData[name] = value; | ||
session.set(name, value); | ||
}); | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ var data_listeners = alchemy.shared('data_binding_listeners'); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.2.0 | ||
* @version 1.3.1 | ||
* @version 1.4.0 | ||
* | ||
* @param {Conduit} conduit The initializing conduit | ||
*/ | ||
|
@@ -14,6 +14,9 @@ var Session = Function.inherits('Alchemy.Base', function ClientSession(conduit) | |
// Register the creation date | ||
this.created = new Date(); | ||
|
||
// The values in the session | ||
this.values = new Map(); | ||
|
||
// Register when the last scene connected | ||
this.last_scene_connection = null; | ||
|
||
|
@@ -135,6 +138,37 @@ Session.setProperty(function is_active() { | |
return false; | ||
}); | ||
|
||
/** | ||
* Set a value in the session | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {*} key | ||
* @param {*} value | ||
*/ | ||
Session.setMethod(function set(key, value) { | ||
if (value === undefined) { | ||
this.values.delete(key); | ||
} else { | ||
this.values.set(key, value); | ||
} | ||
}); | ||
|
||
/** | ||
* Get a value from the session | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.4.0 | ||
* @version 1.4.0 | ||
* | ||
* @param {*} key | ||
*/ | ||
Session.setMethod(function get(key) { | ||
return this.values.get(key); | ||
}); | ||
|
||
/** | ||
* Add the amount of time this client has been in the queue | ||
* | ||
|