mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Add sessionData to 'this' in methods and subscriptions. Just an object that users can write to. Same scope as userId.
Also, convert MethodInvocation to options instead of long parameter list.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// XXX namespacing
|
||||
|
||||
Meteor._MethodInvocation = function (isSimulation, userId,
|
||||
globallySetUserId, unblock) {
|
||||
Meteor._MethodInvocation = function (options) {
|
||||
var self = this;
|
||||
|
||||
// true if we're running not the actual method, but a stub (that is,
|
||||
@@ -11,22 +10,28 @@ Meteor._MethodInvocation = function (isSimulation, userId,
|
||||
// purposes). not currently true except in a client such as a browser,
|
||||
// since there's usually no point in running stubs unless you have a
|
||||
// zero-latency connection to the user.
|
||||
this.isSimulation = isSimulation;
|
||||
this.isSimulation = options.isSimulation;
|
||||
|
||||
// XXX Backwards compatibility only. Remove this before 1.0.
|
||||
this.is_simulation = isSimulation;
|
||||
this.is_simulation = this.isSimulation;
|
||||
|
||||
// call this function to allow other method invocations (from the
|
||||
// same client) to continue running without waiting for this one to
|
||||
// complete.
|
||||
this.unblock = unblock || function () {};
|
||||
this.unblock = options.unblock || function () {};
|
||||
|
||||
// current user id
|
||||
this._userId = userId;
|
||||
this._userId = options.userId;
|
||||
|
||||
// sets current user id in all appropriate server contexts and
|
||||
// reruns subscriptions
|
||||
this._setUserId = globallySetUserId || function () {};
|
||||
this._setUserId = options.setUserId || function () {};
|
||||
|
||||
// Scratch data scoped to this connection (livedata_connection on the
|
||||
// client, livedata_session on the server). This is only used
|
||||
// internally, but we should have real and documented API for this
|
||||
// sort of thing someday.
|
||||
this._sessionData = options.sessionData;
|
||||
};
|
||||
|
||||
_.extend(Meteor._MethodInvocation.prototype, {
|
||||
|
||||
@@ -75,6 +75,10 @@ Meteor._LivedataConnection = function (url, options) {
|
||||
// yet ready.
|
||||
self.sub_ready_callbacks = {};
|
||||
|
||||
// Per-connection scratch area. This is only used internally, but we
|
||||
// should have real and documented API for this sort of thing someday.
|
||||
self.sessionData = {};
|
||||
|
||||
// just for testing
|
||||
self.quiesce_callbacks = [];
|
||||
|
||||
@@ -319,8 +323,11 @@ _.extend(Meteor._LivedataConnection.prototype, {
|
||||
var setUserId = function(userId) {
|
||||
self.setUserId(userId);
|
||||
};
|
||||
var invocation = new Meteor._MethodInvocation(
|
||||
true /* isSimulation */, self.userId(), setUserId);
|
||||
var invocation = new Meteor._MethodInvocation({
|
||||
isSimulation: true,
|
||||
userId: self.userId(), setUserId: setUserId,
|
||||
sessionData: self.sessionData
|
||||
});
|
||||
try {
|
||||
var ret = Meteor._CurrentInvocation.withValue(invocation,function () {
|
||||
return stub.apply(invocation, args);
|
||||
|
||||
@@ -38,6 +38,10 @@ Meteor._LivedataSession = function (server) {
|
||||
self.dontFlush = false;
|
||||
|
||||
self.userId = null;
|
||||
|
||||
// Per-connection scratch area. This is only used internally, but we
|
||||
// should have real and documented API for this sort of thing someday.
|
||||
self.sessionData = {};
|
||||
};
|
||||
|
||||
_.extend(Meteor._LivedataSession.prototype, {
|
||||
@@ -281,8 +285,12 @@ _.extend(Meteor._LivedataSession.prototype, {
|
||||
self._setUserId(userId);
|
||||
};
|
||||
|
||||
var invocation = new Meteor._MethodInvocation(
|
||||
false /* isSimulation */, self.userId, setUserId, unblock);
|
||||
var invocation = new Meteor._MethodInvocation({
|
||||
isSimulation: false,
|
||||
userId: self.userId, setUserId: setUserId,
|
||||
unblock: unblock,
|
||||
sessionData: self.sessionData
|
||||
});
|
||||
try {
|
||||
var ret =
|
||||
Meteor._CurrentWriteFence.withValue(fence, function () {
|
||||
@@ -437,6 +445,12 @@ Meteor._LivedataSubscription = function (session, sub_id, priority) {
|
||||
// LivedataSession
|
||||
this.session = session;
|
||||
|
||||
// Give access to sessionData in subscriptions as well as
|
||||
// methods. This is not currently used, but is included for
|
||||
// consistency. We should have real and documented API for this sort
|
||||
// of thing someday.
|
||||
this._sessionData = session.sessionData;
|
||||
|
||||
// my subscription ID (generated by client, null for universal subs).
|
||||
this.sub_id = sub_id;
|
||||
|
||||
@@ -873,8 +887,11 @@ _.extend(Meteor._LivedataServer.prototype, {
|
||||
};
|
||||
}
|
||||
|
||||
var invocation = new Meteor._MethodInvocation(
|
||||
false /* isSimulation */, userId, setUserId);
|
||||
var invocation = new Meteor._MethodInvocation({
|
||||
isSimulation: false,
|
||||
userId: userId, setUserId: setUserId,
|
||||
sessionData: self.sessionData
|
||||
});
|
||||
try {
|
||||
var ret = Meteor._CurrentInvocation.withValue(invocation, function () {
|
||||
return handler.apply(invocation, args);
|
||||
|
||||
Reference in New Issue
Block a user