Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Makes Alert SSR compatible #66
Browse files Browse the repository at this point in the history
  • Loading branch information
zenorocha committed Feb 16, 2018
1 parent f2c5fff commit b265027
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/marble-alert/src/Alert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {core} from 'metal';
import {core, isServerSide} from 'metal';
import dom from 'metal-dom';
import Anim from 'metal-anim';
import Component from 'metal-component';
Expand All @@ -22,6 +22,10 @@ class Alert extends Component {
* @inheritDoc
*/
detached() {
if (isServerSide()) {
return;
}

super.detached();
this.eventHandler_.removeAllListeners();
clearTimeout(this.delay_);
Expand Down Expand Up @@ -86,6 +90,10 @@ class Alert extends Component {
* @param {boolean} dismissible
*/
syncDismissible(dismissible) {
if (isServerSide()) {
return;
}

if (dismissible) {
this.eventHandler_.add(
dom.on(document, 'click', this.handleDocClick_.bind(this))
Expand Down Expand Up @@ -113,6 +121,10 @@ class Alert extends Component {
* @param {boolean} visible
*/
syncVisible(visible, prevVisible) {
if (isServerSide()) {
return;
}

let shouldAsync = false;
if (!visible) {
dom.once(this.element, 'animationend', this.hideCompletely_.bind(this));
Expand Down
13 changes: 13 additions & 0 deletions packages/marble-alert/test/Alert.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @jest-environment node
*/

import Component from 'metal-component';
import Alert from '../src/Alert';

describe('Alert.node', () => {
it('should not fail on the server side', () => {
const alert = Component.renderToString(Alert);
expect(alert).not.toBeNull();
});
});

0 comments on commit b265027

Please sign in to comment.