Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #269 from Wikia/render-hack-fix
Browse files Browse the repository at this point in the history
Component rendering quick fix -- to preview
  • Loading branch information
rybmat committed Nov 22, 2017
2 parents 5ef4f50 + f639ceb commit 5dc7f8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
24 changes: 4 additions & 20 deletions app/instance-initializers/error-logger.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
import config from '../config/environment';
import fetch from 'fetch';
import logEvent from '../modules/event-logger';
import Ember from 'ember';

export function initialize(/* appInstance */) {
if (typeof FastBoot !== 'undefined') {
return;
}

Ember.onerror = function (error) {
const url = `https://${config.services.domain}/${config.services.eventLogger.baseAPIPath}/error`;

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
// sends cookie with request, allows for logging beaconId and sessionId
credentials: 'include',
body: JSON.stringify({
name: 'Ember.onerror',
description: JSON.stringify({
message: error.message,
stack: error.stack,
}),
client: 'mobile-wiki'
})
logEvent('Ember.onerror', {
message: error.message,
stack: error.stack,
});

// To be able to display it in console
Expand Down
20 changes: 20 additions & 0 deletions app/modules/event-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import config from '../config/environment';
import fetch from 'fetch';

const url = `https://${config.services.domain}/${config.services.eventLogger.baseAPIPath}/error`;

export default function logEvent(name, description) {
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
// sends cookie with request, allows for logging beaconId and sessionId
credentials: 'include',
body: JSON.stringify({
name,
description: JSON.stringify(description),
client: 'mobile-wiki'
})
});
}
12 changes: 10 additions & 2 deletions app/utils/render-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {scheduleOnce} from '@ember/runloop';
import $ from 'jquery';
import {assert} from '@ember/debug';
import {getOwner} from '@ember/application';
import logEvent from '../modules/event-logger';

function componentAttributes(element) {
const attrsJSON = element.getAttribute('data-attrs');
Expand Down Expand Up @@ -43,8 +44,15 @@ export function getRenderComponentFor(parent) {
componentInstance.renderer.appendTo(componentInstance, placeholderElement.parentNode);

scheduleOnce('afterRender', this, () => {
placeholderElement.parentNode.insertBefore(componentInstance.element, placeholderElement);
$(placeholderElement).remove();
if (componentInstance.element instanceof Node) {
placeholderElement.parentNode.insertBefore(componentInstance.element, placeholderElement);
$(placeholderElement).remove();
} else {
logEvent('render-component--element', {
componentName: name,
componentInstanceElement: JSON.stringify(componentInstance.element),
});
}
});

return componentInstance;
Expand Down

0 comments on commit 5dc7f8d

Please sign in to comment.