Skip to content

Commit

Permalink
remove JsSse::$closeBeforeUnload prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 30, 2025
1 parent b4fc2d6 commit e44ba72
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
12 changes: 5 additions & 7 deletions js/src/JqueryPlugin/ServerEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class AtkServerEventPlugin extends AbstractPlugin {
const hasLoader = this.settings.showLoader;

this.source = new EventSource(this.settings.url);

if (hasLoader) {
element.addClass('loading');
}
Expand All @@ -17,22 +18,20 @@ export default class AtkServerEventPlugin extends AbstractPlugin {

this.source.addEventListener('error', (e) => {
if (e.eventPhase === EventSource.CLOSED) {
this.source.close();

if (hasLoader) {
element.removeClass('loading');
}
this.source.close();
}
});

this.source.addEventListener('atkSseAction', (e) => {
atk.apiService.atkProcessExternalResponse(JSON.parse(e.data));
});

if (this.settings.closeBeforeUnload) {
window.addEventListener('beforeunload', (event) => {
this.source.close();
});
}
// prevent "The connection to http://xxx was interrupted while the page was loading." browser console warning
window.addEventListener('beforeunload', () => this.source.close());
}

stop() {
Expand All @@ -48,5 +47,4 @@ AtkServerEventPlugin.DEFAULTS = {
url: null,
urlOptions: {},
showLoader: false,
closeBeforeUnload: false,
};
13 changes: 5 additions & 8 deletions public/js/atkjs-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1775,20 +1775,18 @@ class AtkServerEventPlugin extends _AbstractPlugin__WEBPACK_IMPORTED_MODULE_2__[
});
this.source.addEventListener('error', e => {
if (e.eventPhase === EventSource.CLOSED) {
this.source.close();
if (hasLoader) {
element.removeClass('loading');
}
this.source.close();
}
});
this.source.addEventListener('atkSseAction', e => {
atk__WEBPACK_IMPORTED_MODULE_1__["default"].apiService.atkProcessExternalResponse(JSON.parse(e.data));
});
if (this.settings.closeBeforeUnload) {
window.addEventListener('beforeunload', event => {
this.source.close();
});
}

// prevent "The connection to http://xxx was interrupted while the page was loading." browser console warning
window.addEventListener('beforeunload', () => this.source.close());
}
stop() {
this.source.close();
Expand All @@ -1800,8 +1798,7 @@ class AtkServerEventPlugin extends _AbstractPlugin__WEBPACK_IMPORTED_MODULE_2__[
AtkServerEventPlugin.DEFAULTS = {
url: null,
urlOptions: {},
showLoader: false,
closeBeforeUnload: false
showLoader: false
};

/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion public/js/atkjs-ui.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/atkjs-ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/atkjs-ui.min.js.map

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/JsSse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class JsSse extends JsCallback
/** @var bool Show Loader when doing SSE. */
public $showLoader = false;

/** @var bool Add window.beforeunload listener for closing js EventSource. Off by default. */
public $closeBeforeUnload = false;

/** @var \Closure(string): void|null Custom function for outputting (instead of echo). */
public $echoFunction;

Expand All @@ -33,9 +30,6 @@ public function jsExecute(): JsBlock
if ($this->showLoader) {
$options['showLoader'] = $this->showLoader;
}
if ($this->closeBeforeUnload) {
$options['closeBeforeUnload'] = $this->closeBeforeUnload;
}

return new JsBlock([(new Jquery($this->getOwner() /* TODO element and loader element should be passed explicitly */))->atkServerEvent($options)]);
}
Expand Down

0 comments on commit e44ba72

Please sign in to comment.