Skip to content

Commit

Permalink
Simplify _startupCallback by passing callback rather than ID.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Nov 6, 2019
1 parent e17b52a commit ec0ed4d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
12 changes: 5 additions & 7 deletions packages/accounts-base/accounts_client.js
Expand Up @@ -441,16 +441,14 @@ export class AccountsClient extends AccountsCommon {
// at registration time if already logged in
// this can happen when new AccountsClient is created
// before callbacks are registered see #10157
_startupCallback(callbackId) {
_startupCallback(callback) {
// Are we already logged in?
if (this.connection._userId) {
// Then go ahead and call the callback that we just registered.
const cb = this._onLoginHook.callbacks[callbackId];
// If already logged in before handler is registered, it's safe to
// assume type is a 'resume', and execute the callback at the end of
// the queue so that Meteor.startup can complete before any embedded
// onLogin callbacks would execute.
Meteor.setTimeout(() => cb({ type: 'resume' }), 0);
// assume type is a 'resume', so we execute the callback at the end
// of the queue so that Meteor.startup can complete before any
// embedded onLogin callbacks would execute.
Meteor.setTimeout(() => callback({ type: 'resume' }), 0);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/accounts-base/accounts_common.js
Expand Up @@ -198,7 +198,7 @@ export class AccountsCommon {
onLogin(func) {
let ret = this._onLoginHook.register(func);
// call the just registered callback if already logged in
this._startupCallback(this._onLoginHook.nextCallbackId - 1);
this._startupCallback(ret.callback);
return ret;
}

Expand Down Expand Up @@ -289,8 +289,8 @@ export class AccountsCommon {
return new Date() > (new Date(when) - minLifetimeMs);
}

// noop on the server overridden on the client
_startupCallback(callbackId) {}
// No-op on the server, overridden on the client.
_startupCallback(callback) {}
}

// Note that Accounts is defined separately in accounts_client.js and
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-base/package.js
@@ -1,6 +1,6 @@
Package.describe({
summary: "A user account system",
version: "1.4.4",
version: "1.4.5",
});

Package.onUse(api => {
Expand Down
1 change: 1 addition & 0 deletions packages/callback-hook/hook.js
Expand Up @@ -77,6 +77,7 @@ export class Hook {
this.callbacks[id] = callback;

return {
callback,
stop: () => {
delete this.callbacks[id];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/callback-hook/package.js
@@ -1,6 +1,6 @@
Package.describe({
summary: "Register callbacks on a hook",
version: '1.1.0'
version: '1.2.0'
});

Package.onUse(function (api) {
Expand Down

0 comments on commit ec0ed4d

Please sign in to comment.