Skip to content

Commit

Permalink
fix: #237 - replacing Ember.Logger with console (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
cs3b authored and machty committed Jan 29, 2019
1 parent c541713 commit 22c4f6d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
9 changes: 6 additions & 3 deletions addon/-task-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ let taskInstanceAttrs = {
value = new Error(this.cancelReason);

if (this._debug || Ember.ENV.DEBUG_TASKS) {
Ember.Logger.log(this.cancelReason);
// eslint-disable-next-line no-console
console.log(this.cancelReason);
}

value.name = TASK_CANCELATION_NAME;
Expand Down Expand Up @@ -544,7 +545,8 @@ let taskInstanceAttrs = {
} finally {
if (this._expectsLinkedYield) {
if (!this._generatorValue || this._generatorValue._performType !== PERFORM_TYPE_LINKED) {
Ember.Logger.warn("You performed a .linked() task without immediately yielding/returning it. This is currently unsupported (but might be supported in future version of ember-concurrency).");
// eslint-disable-next-line no-console
console.warn("You performed a .linked() task without immediately yielding/returning it. This is currently unsupported (but might be supported in future version of ember-concurrency).");
}
this._expectsLinkedYield = false;
}
Expand Down Expand Up @@ -783,7 +785,8 @@ taskInstanceAttrs[yieldableSymbol] = function handleYieldedTaskInstance(parentTa
get(yieldedTaskInstance, 'isRunning')) {
let parentName = `\`${parentTaskInstance.task._propertyName}\``;
let childName = `\`${yieldedTaskInstance.task._propertyName}\``;
Ember.Logger.warn(`ember-concurrency detected a potentially hazardous "self-cancel loop" between parent task ${parentName} and child task ${childName}. If you want child task ${childName} to be canceled when parent task ${parentName} is canceled, please change \`.perform()\` to \`.linked().perform()\`. If you want child task ${childName} to keep running after parent task ${parentName} is canceled, change it to \`.unlinked().perform()\``);
// eslint-disable-next-line no-console
console.warn(`ember-concurrency detected a potentially hazardous "self-cancel loop" between parent task ${parentName} and child task ${childName}. If you want child task ${childName} to be canceled when parent task ${parentName} is canceled, please change \`.perform()\` to \`.linked().perform()\`. If you want child task ${childName} to keep running after parent task ${parentName} is canceled, change it to \`.unlinked().perform()\``);
}
}
yieldedTaskInstance.cancel();
Expand Down
4 changes: 2 additions & 2 deletions addon/-task-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { addObserver } from '@ember/object/observers';
import { addListener } from '@ember/object/events';
import EmberObject from '@ember/object';
import { getOwner } from '@ember/application';
import Ember from 'ember';
import {
default as TaskInstance,
getRunningInstance
Expand Down Expand Up @@ -442,7 +441,8 @@ export class TaskProperty extends _ComputedProperty {
super.setup(...arguments);
}
if (this._maxConcurrency !== Infinity && !this._hasSetBufferPolicy) {
Ember.Logger.warn(`The use of maxConcurrency() without a specified task modifier is deprecated and won't be supported in future versions of ember-concurrency. Please specify a task modifier instead, e.g. \`${taskName}: task(...).enqueue().maxConcurrency(${this._maxConcurrency})\``);
// eslint-disable-next-line no-console
console.warn(`The use of maxConcurrency() without a specified task modifier is deprecated and won't be supported in future versions of ember-concurrency. Please specify a task modifier instead, e.g. \`${taskName}: task(...).enqueue().maxConcurrency(${this._maxConcurrency})\``);
}

registerOnPrototype(addListener, proto, this.eventNames, taskName, 'perform', false);
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/deprecations-test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* eslint-disable no-console */
import { run } from '@ember/runloop';
import EmberObject from '@ember/object';
import Ember from 'ember';
import { task } from 'ember-concurrency';
import { module, test } from 'qunit';

const originalWarn = Ember.Logger.warn;
const originalWarn = console.warn;
let warnings;

module('Deprecations', function(hooks) {
hooks.beforeEach(function() {
warnings = [];
Ember.Logger.warn = (w) => {
console.warn = (w) => {
warnings.push(w);
};
});

hooks.afterEach(function() {
Ember.Logger.warn = originalWarn;
console.warn = originalWarn;
});

test("warn if using maxConcurrency without specifying other task modifier", function(assert) {
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/task-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { defer } from 'rsvp';
import { A } from '@ember/array';
import Evented from '@ember/object/evented';
Expand All @@ -7,13 +8,13 @@ import Ember from 'ember';
import { task, timeout, forever } from 'ember-concurrency';
import { module, test } from 'qunit';

const originalLog = Ember.Logger.log;
const originalWarn = Ember.Logger.warn;
const originalLog = console.log;
const originalWarn = console.warn;

module('Unit: task', function(hooks) {
hooks.afterEach(function() {
Ember.Logger.log = originalLog;
Ember.Logger.warn = originalWarn;
console.log = originalLog;
console.warn = originalWarn;
Ember.ENV.DEBUG_TASKS = false;
});

Expand Down Expand Up @@ -452,7 +453,7 @@ module('Unit: task', function(hooks) {
assert.expect(1);

let logs = [];
Ember.Logger.log = (...args) => {
console.log = (...args) => {
logs.push(args);
};

Expand Down Expand Up @@ -481,7 +482,7 @@ module('Unit: task', function(hooks) {
Ember.ENV.DEBUG_TASKS = true;

let logs = [];
Ember.Logger.log = (...args) => {
console.log = (...args) => {
logs.push(args);
};

Expand Down Expand Up @@ -535,7 +536,7 @@ module('Unit: task', function(hooks) {
assert.expect(2);

let warnings = [];
Ember.Logger.warn = (...args) => {
console.warn = (...args) => {
warnings.push(args);
};

Expand Down Expand Up @@ -606,7 +607,7 @@ module('Unit: task', function(hooks) {
assert.expect(1);

let warnings = [];
Ember.Logger.warn = (...args) => {
console.warn = (...args) => {
warnings.push(args);
};

Expand Down

0 comments on commit 22c4f6d

Please sign in to comment.