Permalink
Browse files

Checks if a component is being initialized on the server side #109

  • Loading branch information...
zenorocha authored and Robert-Frampton committed Feb 16, 2018
1 parent 74ab204 commit 4ecbd9470b21794dc67ed74fd5c70d2b9f78ddb4
@@ -1,11 +1,16 @@
'use strict';
import {isServerSide} from 'metal';
import Clipboard from 'metal-clipboard';
import Component from 'metal-component';
import Tooltip from 'metal-tooltip';
class ElectricCode extends Component {
attached() {
if (isServerSide()) {
return;
}
const selector = '.code-container .btn-copy';
if (!window.electricClipboardTooltip) {
@@ -1,5 +1,6 @@
'use strict';
import {isServerSide} from 'metal';
import Affix from 'metal-affix';
import Component from 'metal-component';
import core from 'metal';
@@ -8,6 +9,10 @@ import ReadingProgress from 'metal-reading-progress';
class ElectricReadingProgress extends Component {
attached() {
if (isServerSide()) {
return;
}
this.renderReadingProgress_();
}
@@ -1,11 +1,16 @@
'use strict';
import {isServerSide} from 'metal';
import core from 'metal';
import ElectricSearchBase from './ElectricSearchBase';
class ElectricSearch extends ElectricSearchBase {
attached() {
if (isServerSide()) {
return;
}
ElectricSearchBase.prototype.attached.apply(this);
const queryString = window.location.search;
@@ -7,22 +7,24 @@ import ElectricSearchBase from './ElectricSearchBase';
class ElectricSearchAutocomplete extends ElectricSearchBase {
attached() {
if (!isServerSide()) {
const {element} = this;
const {input} = this.refs;
if (input) {
this.autocomplete = new Autocomplete({
autoBestAlign: false,
data: this.search_.bind(this),
format: this.format_.bind(this),
inputElement: input,
select: ({url}) => {
window.location = url;
}
});
}
if (isServerSide()) {
return;
}
const {element} = this;
const {input} = this.refs;
if (input) {
this.autocomplete = new Autocomplete({
autoBestAlign: false,
data: this.search_.bind(this),
format: this.format_.bind(this),
inputElement: input,
select: ({url}) => {
window.location = url;
}
});
}
}
@@ -1,5 +1,6 @@
'use strict';
import {isServerSide} from 'metal';
import Ajax from 'metal-ajax';
import Autocomplete from 'metal-autocomplete';
import Component from 'metal-component';
@@ -8,6 +9,10 @@ import Promise from 'metal-promise';
class ElectricAPIAutocomplete extends Component {
attached() {
if (isServerSide()) {
return;
}
this.autocomplete = new Autocomplete({
autoBestAlign: false,
data: this.search_.bind(this),
@@ -3,11 +3,16 @@
import Toggler from 'metal-toggler';
import Soy from 'metal-soy';
import ElectricNavigationBase from 'electric-base-components';
import {isServerSide} from 'metal';
import templates from './ElectricNavigation.soy';
class ElectricNavigation extends ElectricNavigationBase {
attached() {
if (isServerSide()) {
return;
}
this.toggler = new Toggler({
content: `.${this.listClasses}`,
header: `.${this.togglerClasses}`,
@@ -31,4 +36,4 @@ ElectricNavigation.STATE = {
Soy.register(ElectricNavigation, templates);
export default ElectricNavigation;
export default ElectricNavigation;
@@ -1,5 +1,6 @@
'use strict';
import {isServerSide} from 'metal';
import Component from 'metal-component';
import Soy from 'metal-soy';
import Toggler from 'metal-toggler';
@@ -8,14 +9,22 @@ import templates from './Sidebar.soy.js';
class Sidebar extends Component {
attached() {
this._toggler = new Toggler({
if (isServerSide()) {
return;
}
this.toggler = new Toggler({
content: '.sidebar-toggler-content',
header: '.sidebar-header'
});
}
disposed() {
this._toggler.dispose();
const {toggler} = this;
if (toggler) {
this.toggler.dispose();
}
}
};
@@ -1,16 +1,23 @@
'use strict';
import {isServerSide} from 'metal';
import Component from 'metal-component';
import Soy from 'metal-soy';
import templates from './SocialButtons.soy.js';
class SocialButtons extends Component {
rendered() {
this.siteUrl = window.location.origin;
}
attached() {
if (isServerSide()) {
return;
}
}
rendered() {
this.siteUrl = window.location.origin;
}
};
Soy.register(SocialButtons, templates);
export default SocialButtons;
export default SocialButtons;
@@ -1,18 +1,20 @@
'use strict';
import {isServerSide} from 'metal';
import Component from 'metal-component';
import Soy from 'metal-soy';
import moment from 'moment';
import {addClasses, hasClass} from 'metal-dom';
import {isServerSide} from 'metal';
import templates from './TutorialTimer.soy.js';
class TutorialTimer extends Component {
attached() {
if (!isServerSide()) {
this.time = this.calculateTimeRemaining();
if (isServerSide()) {
return;
}
this.time = this.calculateTimeRemaining();
}
calculateTimeRemaining() {
@@ -77,4 +79,4 @@ TutorialTimer.STATE = {
Soy.register(TutorialTimer, templates);
export default TutorialTimer;
export default TutorialTimer;

0 comments on commit 4ecbd94

Please sign in to comment.