Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable Accounts constructors #4233

Closed
wants to merge 7 commits into from
Closed

Conversation

benjamn
Copy link
Contributor

@benjamn benjamn commented Apr 17, 2015

This pull requests reduces the assumption of a singleton Accounts namespace in the accounts-base core package, making it much easier to manage multiple accounts connections without duplicating code.

At a high level, this refactoring was all about replacing the ad-hoc Accounts object with instances of the new AccountsClient and AccountsServer classes, which inherit from AccountsCommon so that methods can be shared (yay isomorphism!).

As an example of a luxury that had to be given up in order to support multiple accounts instances, initialization code that used to run at the top level (like the auto-login code) is now called from the constructor functions.

I think it's now much clearer which methods and properties are available on the client, on the server, or in both places, since each environment has a distinct .prototype where available methods are defined.

this._initLocalStorage();
};

var Ap = AccountsClient.prototype =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inheritance dance will become much cleaner when we enable ES6 class syntax in core packages.

@benjamn benjamn force-pushed the reusable-accounts-constructors branch from 433df8f to a608173 Compare April 20, 2015 03:21
@benjamn
Copy link
Contributor Author

benjamn commented Apr 20, 2015

There's an argument in favor of making AccountsClient available on both client and server, since server code might need to act as a client to an accounts server, too. I don't need that functionality yet, but it's something to think about.

Ben Newman added 7 commits May 12, 2015 12:43
This involves moving Accounts.* methods defined in accounts_common.js onto
AccountsCommon.prototype.*.
Note that this constructor inherits from the AccountsCommon constructor.
Naturally both of these constructor functions should become classes once
we have support for ES6 classes.
There's an argument in favor of making AccountsClient available on both
client and server, since server code might need to act as a client to an
accounts server, too. I don't need that functionality yet, but it's
something to think about.
Also share urls.* methods between all AccountsServer instances.
@benjamn benjamn force-pushed the reusable-accounts-constructors branch from aaa4309 to a2d588d Compare May 12, 2015 17:43
@benjamn
Copy link
Contributor Author

benjamn commented May 14, 2015

Closed via ff5fb16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants