1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Make JX.Aphlict a real singleton with a more sensible initialization order

Summary:
Ref T5373. The control flow between `aphlict-listener` and `JX.Aphlict` is pretty weird right now, where the listener (which is the highest-level component) has intimate knowledge of how to put the SWF on the page.

Instead:

  - Make `JX.Aphlict` a real singleton.
  - Instantiate it sooner.
  - Have it handle the flash setup handshake.

Test Plan: Loaded page in debug mode, saw normal flow take place.

Reviewers: joshuaspence

Reviewed By: joshuaspence

Subscribers: epriestley

Maniphest Tasks: T5373

Differential Revision: https://secure.phabricator.com/D9699
This commit is contained in:
epriestley 2014-06-23 15:19:34 -07:00
parent 80f26e96ea
commit dd91732df3
6 changed files with 105 additions and 84 deletions

View file

@ -8,7 +8,7 @@ return array(
'names' =>
array(
'core.pkg.css' => '22e4fc33',
'core.pkg.js' => '941224f2',
'core.pkg.js' => 'f5ba2408',
'darkconsole.pkg.js' => 'df001cab',
'differential.pkg.css' => '4a93db37',
'differential.pkg.js' => 'd1443567',
@ -346,9 +346,9 @@ return array(
'rsrc/image/texture/table_header.png' => '5c433037',
'rsrc/image/texture/table_header_hover.png' => '038ec3b9',
'rsrc/image/texture/table_header_tall.png' => 'd56b434f',
'rsrc/js/application/aphlict/Aphlict.js' => '08be8878',
'rsrc/js/application/aphlict/Aphlict.js' => 'da12704d',
'rsrc/js/application/aphlict/behavior-aphlict-dropdown.js' => '862ea0fe',
'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'bdb2032d',
'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'a826c925',
'rsrc/js/application/auth/behavior-persona-login.js' => '9414ff18',
'rsrc/js/application/config/behavior-reorder-fields.js' => '14a827de',
'rsrc/js/application/conpherence/behavior-menu.js' => 'f0a41b9f',
@ -490,7 +490,7 @@ return array(
'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8',
'rsrc/js/phuix/PHUIXActionView.js' => '6e8cefa4',
'rsrc/js/phuix/PHUIXDropdownMenu.js' => 'bd4c8dca',
'rsrc/swf/aphlict.swf' => '14d5aa2e',
'rsrc/swf/aphlict.swf' => 'ef64606d',
),
'symbols' =>
array(
@ -539,10 +539,10 @@ return array(
'herald-rule-editor' => '6c9e6fb8',
'herald-test-css' => '778b008e',
'inline-comment-summary-css' => '8cfd34e8',
'javelin-aphlict' => '08be8878',
'javelin-aphlict' => 'da12704d',
'javelin-behavior' => '8a3ed18b',
'javelin-behavior-aphlict-dropdown' => '862ea0fe',
'javelin-behavior-aphlict-listen' => 'bdb2032d',
'javelin-behavior-aphlict-listen' => 'a826c925',
'javelin-behavior-aphront-basic-tokenizer' => 'b3a4b884',
'javelin-behavior-aphront-crop' => 'fa0f4fc2',
'javelin-behavior-aphront-drag-and-drop-textarea' => '92eb531d',
@ -878,11 +878,6 @@ return array(
3 => 'javelin-vector',
4 => 'javelin-stratcom',
),
'08be8878' =>
array(
0 => 'javelin-install',
1 => 'javelin-util',
),
'08e56a4e' =>
array(
0 => 'javelin-install',
@ -1279,6 +1274,13 @@ return array(
1 => 'javelin-stratcom',
2 => 'javelin-dom',
),
'62e18640' =>
array(
0 => 'javelin-install',
1 => 'javelin-util',
2 => 'javelin-dom',
3 => 'javelin-typeahead-normalizer',
),
'6453c869' =>
array(
0 => 'javelin-install',
@ -1357,13 +1359,6 @@ return array(
0 => 'javelin-behavior',
1 => 'javelin-dom',
),
'62e18640' =>
array(
0 => 'javelin-install',
1 => 'javelin-util',
2 => 'javelin-dom',
3 => 'javelin-typeahead-normalizer',
),
'76b9fc3e' =>
array(
0 => 'javelin-behavior',
@ -1642,6 +1637,19 @@ return array(
1 => 'javelin-stratcom',
2 => 'javelin-dom',
),
'a826c925' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-aphlict',
2 => 'javelin-stratcom',
3 => 'javelin-request',
4 => 'javelin-uri',
5 => 'javelin-dom',
6 => 'javelin-json',
7 => 'javelin-router',
8 => 'javelin-util',
9 => 'phabricator-notification',
),
'a82a7769' =>
array(
0 => 'javelin-behavior',
@ -1794,18 +1802,6 @@ return array(
2 => 'javelin-util',
3 => 'javelin-request',
),
'bdb2032d' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-aphlict',
2 => 'javelin-stratcom',
3 => 'javelin-request',
4 => 'javelin-uri',
5 => 'javelin-dom',
6 => 'javelin-json',
7 => 'javelin-router',
8 => 'phabricator-notification',
),
'bdb3e4d0' =>
array(
0 => 'javelin-behavior',
@ -1925,6 +1921,11 @@ return array(
1 => 'javelin-util',
2 => 'javelin-stratcom',
),
'da12704d' =>
array(
0 => 'javelin-install',
1 => 'javelin-util',
),
'dd7e8ef5' =>
array(
0 => 'javelin-behavior',

View file

@ -42,6 +42,10 @@ package {
this.externalInvoke('log', message);
}
final protected function setStatus(status:String):void {
this.externalInvoke('status', {type: status});
}
}
}

View file

@ -42,11 +42,8 @@ package {
this.uncaughtErrorHandler);
ExternalInterface.addCallback('connect', this.externalConnect);
ExternalInterface.call(
'JX.Stratcom.invoke',
'aphlict-component-ready',
null,
{});
this.setStatus('ready');
}
private function uncaughtErrorHandler(event:UncaughtErrorEvent):void {
@ -58,8 +55,6 @@ package {
port:Number,
subscriptions:Array):void {
this.externalInvoke('connect');
this.remoteServer = server;
this.remotePort = port;
this.subscriptions = subscriptions;

View file

@ -25,51 +25,87 @@
*/
JX.install('Aphlict', {
construct : function(id, server, port, subscriptions) {
construct: function(id, server, port, subscriptions) {
if (__DEV__) {
if (JX.Aphlict._instance) {
JX.$E('Aphlict object is sort of a singleton..!');
JX.$E('Aphlict object is a singleton!');
}
}
JX.Aphlict._instance = this;
this._id = id;
this._server = server;
this._port = port;
this._subscriptions = subscriptions;
// Flash puts its "objects" into global scope in an inconsistent way,
// because it was written in like 1816 when globals were awesome and IE4
// didn't support other scopes since global scope is the best anyway.
var container = document[id] || window[id];
this._flashContainer = container;
JX.Aphlict._instance = this;
},
members : {
_server : null,
_port : null,
_subscriptions : null,
start : function() {
members: {
_id: null,
_server: null,
_port: null,
_subscriptions: null,
start: function(node, uri) {
// NOTE: This is grotesque, but seems to work everywhere.
node.innerHTML =
'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">' +
'<param name="movie" value="' + uri + '" />' +
'<param name="allowScriptAccess" value="always" />' +
'<param name="wmode" value="opaque" />' +
'<embed src="' + uri + '" wmode="opaque"' +
'width="0" height="0" id="' + this._id + '">' +
'</embed>' +
'</object>';
},
_didStartFlash: function() {
var id = this._id;
// Flash puts its "objects" into global scope in an inconsistent way,
// because it was written in like 1816 when globals were awesome and IE4
// didn't support other scopes since global scope is the best anyway.
var container = document[id] || window[id];
this._flashContainer = container;
this._flashContainer.connect(
this._server,
this._port,
this._subscriptions);
}
},
properties : {
handler : null
properties: {
handler: null
},
statics : {
_instance : null,
didReceiveEvent : function(type, message) {
if (!JX.Aphlict._instance) {
statics: {
_instance: null,
getInstance: function() {
var self = JX.Aphlict;
if (!self._instance) {
return null;
}
return self._instance;
},
didReceiveEvent: function(type, message) {
var client = JX.Aphlict.getInstance();
if (!client) {
return;
}
var handler = JX.Aphlict._instance.getHandler();
if (type == 'status') {
switch (message.type) {
case 'ready':
client._didStartFlash();
break;
}
}
var handler = client.getHandler();
if (handler) {
handler(type, message);
}

View file

@ -16,18 +16,6 @@ JX.behavior('aphlict-listen', function(config) {
var showing_reload = false;
function onready() {
var client = new JX.Aphlict(
config.id,
config.server,
config.port,
config.subscriptions);
client
.setHandler(onaphlictmessage)
.start();
}
JX.Stratcom.listen('aphlict-receive-message', null, function(e) {
var message = e.getData();
@ -61,6 +49,8 @@ JX.behavior('aphlict-listen', function(config) {
default:
case 'error':
case 'log':
case 'status':
if (config.debug) {
var details = message ? JX.JSON.stringify(message) : '';
JX.log('(Aphlict) [' + type + '] ' + details);
@ -98,19 +88,14 @@ JX.behavior('aphlict-listen', function(config) {
}
}
var client = new JX.Aphlict(
config.id,
config.server,
config.port,
config.subscriptions);
// Wait for the element to load, and don't do anything if it never loads.
// If we just go crazy and start making calls to it before it loads, its
// interfaces won't be registered yet.
JX.Stratcom.listen('aphlict-component-ready', null, onready);
client
.setHandler(onaphlictmessage)
.start(JX.$(config.containerID), config.swfURI);
// Add Flash object to page
JX.$(config.containerID).innerHTML =
'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">' +
'<param name="movie" value="' + config.swfURI + '" />' +
'<param name="allowScriptAccess" value="always" />' +
'<param name="wmode" value="opaque" />' +
'<embed src="' + config.swfURI + '" wmode="opaque"' +
'width="0" height="0" id="' + config.id + '">' +
'</embed></object>'; //Evan sanctioned
});

Binary file not shown.