GPII/prefsEditors — pull request #36 by chrispetsos (2014-02-24 11:51:58+00:00)
Title: GPII-546: When moving from PCP to PMT, settings are brought along and a new user is NOT created.

Link to JIRA: http://issues.gpii.net/browse/GPII-546
Problem that this pull request solves:

After merging of https://github.com/GPII/prefsEditors/pull/27 for "GPII-549 - "Full Editor" button in the PCP should save settings and switch to the PMT" i performed some tests to see if "GPII-546 - When moving from PCP to PMT, settings should be brought along and a new user should NOT be created" is working properly and i noticed a problem there.
I saw that a wiring of events and invokers was implemented,
https://github.com/chrispetsos/prefsEditors/blob/GPII-546/src/shared/adjusters/js/prefsEditor.js#L25-L31
https://github.com/chrispetsos/prefsEditors/blob/GPII-546/src/shared/adjusters/js/prefsEditor.js#L55-L71
in order to perform the "save and move to PMT" functionality. Although i cannot exactly understand how those "onSetSuccess" and "onRequestPageTransition" events nested inside the "onPageTransition" event get fired, i saw that finally the invoker that refreshes the AT applications,
https://github.com/chrispetsos/prefsEditors/blob/GPII-546/src/shared/common/GpiiStore.js#L133-L155
got fired, or better almost got fired... To me it looked like some strange race condition on when this was invoked,
https://github.com/chrispetsos/prefsEditors/blob/731abeba68a8e315845574dce3020958d24ee648/src/shared/adjusters/js/prefsEditor.js#L64-L71
in parallel with the invoker that refreshes the AT applications. I've tried the test of clicking the "Full Editor" link in PCP many times and as far as i could tell only the "logout" of the refresh of the ATs got fired. The "login" wasn't given time to be invoked and the change of window location happened before it.
The bottom line was that when the user moved from PCP to PMT, the system was in the state where a user was not logged in. So, "When moving from PCP to PMT, settings were not brought along and a new user was created" thus GPII-546 was broken.

Making the GPIIStore's "set" non-async and tweaking a bit the wiring of "save and move to PMT" events and invokers solved this problem.