Skip to content

Commit

Permalink
Merge pull request #16113 from williamhaley/update-ember-debug-docs
Browse files Browse the repository at this point in the history
Update docs for RFC 176 syntax and canonical URL
  • Loading branch information
toddjordan authored Jan 12, 2018
2 parents 7981546 + 5d3fa3c commit ee85052
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
12 changes: 7 additions & 5 deletions packages/ember-debug/lib/deprecate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { registerHandler as genericRegisterHandler, invoke } from './handlers';
*/
/**
Allows for runtime registration of handler functions that override the default deprecation behavior.
Deprecations are invoked by calls to [Ember.deprecate](https://emberjs.com/api/classes/Ember.html#method_deprecate).
Deprecations are invoked by calls to [@ember/application/deprecations/deprecate](https://emberjs.com/api/ember/release/classes/@ember%2Fapplication%2Fdeprecations/methods/deprecate?anchor=deprecate).
The following example demonstrates its usage by registering a handler that throws an error if the
message contains the word "should", otherwise defers to the default handler.
```javascript
Ember.Debug.registerDeprecationHandler((message, options, next) => {
import { registerDeprecationHandler } from '@ember/debug';
registerDeprecationHandler((message, options, next) => {
if (message.indexOf('should') !== -1) {
throw new Error(`Deprecation message with should: ${message}`);
} else {
Expand Down Expand Up @@ -126,11 +128,11 @@ if (DEBUG) {
}
});

missingOptionsDeprecation = 'When calling `Ember.deprecate` you ' +
missingOptionsDeprecation = 'When calling `deprecate` you ' +
'must provide an `options` hash as the third parameter. ' +
'`options` should include `id` and `until` properties.';
missingOptionsIdDeprecation = 'When calling `Ember.deprecate` you must provide `id` in options.';
missingOptionsUntilDeprecation = 'When calling `Ember.deprecate` you must provide `until` in options.';
missingOptionsIdDeprecation = 'When calling `deprecate` you must provide `id` in options.';
missingOptionsUntilDeprecation = 'When calling `deprecate` you must provide `until` in options.';
/**
@module @ember/application
@public
Expand Down
6 changes: 4 additions & 2 deletions packages/ember-debug/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ if (DEBUG) {
* In a production build, this method is defined as an empty function (NOP).
```javascript
Ember.oldMethod = Ember.deprecateFunc('Please use the new, updated method', Ember.newMethod);
import { deprecateFunc } from '@ember/application/deprecations';
Ember.oldMethod = deprecateFunc('Please use the new, updated method', options, Ember.newMethod);
```
@method deprecateFunc
@static
@for @ember/application/deprecations
@param {String} message A description of the deprecation.
@param {Object} [options] The options object for Ember.deprecate.
@param {Object} [options] The options object for `deprecate`.
@param {Function} func The new function called to replace its deprecated counterpart.
@return {Function} A new function that wraps the original function with a deprecation warning
@private
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-debug/lib/warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let missingOptionsDeprecation, missingOptionsIdDeprecation;
if (DEBUG) {
/**
Allows for runtime registration of handler functions that override the default warning behavior.
Warnings are invoked by calls made to [warn](https://emberjs.com/api/classes/Ember.html#method_warn).
Warnings are invoked by calls made to [@ember/debug/warn](https://emberjs.com/api/ember/release/classes/@ember%2Fdebug/methods/warn?anchor=warn).
The following example demonstrates its usage by registering a handler that does nothing overriding Ember's
default warning behavior.
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-debug/tests/error_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from 'internal-test-helpers';

moduleFor('Ember Error Throwing', class extends TestCase {
['@test new Ember.Error displays provided message'](assert) {
['@test new EmberError displays provided message'](assert) {
assert.throws(() => {
throw new EmberError('A Message');
}, e => e.message === 'A Message', 'the assigned message was displayed');
Expand Down
36 changes: 18 additions & 18 deletions packages/ember-debug/tests/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ moduleFor('ember-debug', class extends TestCase {
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = originalDeprecationOptions;
}

['@test Ember.deprecate does not throw if RAISE_ON_DEPRECATION is false'](assert) {
['@test deprecate does not throw if RAISE_ON_DEPRECATION is false'](assert) {
assert.expect(1);

ENV.RAISE_ON_DEPRECATION = false;

try {
deprecate('Should not throw', false, { id: 'test', until: 'forever' });
assert.ok(true, 'Ember.deprecate did not throw');
assert.ok(true, 'deprecate did not throw');
} catch (e) {
assert.ok(false, `Expected deprecate not to throw but it did: ${e.message}`);
}
}

['@test Ember.deprecate resets deprecation level to RAISE if ENV.RAISE_ON_DEPRECATION is set'](assert) {
['@test deprecate resets deprecation level to RAISE if ENV.RAISE_ON_DEPRECATION is set'](assert) {
assert.expect(2);

ENV.RAISE_ON_DEPRECATION = false;

try {
deprecate('Should not throw', false, { id: 'test', until: 'forever' });
assert.ok(true, 'Ember.deprecate did not throw');
assert.ok(true, 'deprecate did not throw');
} catch (e) {
assert.ok(false, `Expected deprecate not to throw but it did: ${e.message}`);
}
Expand Down Expand Up @@ -113,15 +113,15 @@ moduleFor('ember-debug', class extends TestCase {
}, /Should throw with non-matching id/);
}

['@test Ember.deprecate throws deprecation if second argument is falsy'](assert) {
['@test deprecate throws deprecation if second argument is falsy'](assert) {
assert.expect(3);

assert.throws(() => deprecate('Deprecation is thrown', false, { id: 'test', until: 'forever' }));
assert.throws(() => deprecate('Deprecation is thrown', '', { id: 'test', until: 'forever' }));
assert.throws(() => deprecate('Deprecation is thrown', 0, { id: 'test', until: 'forever' }));
}

['@test Ember.deprecate does not invoke a function as the second argument'](assert) {
['@test deprecate does not invoke a function as the second argument'](assert) {
assert.expect(1);

deprecate('Deprecation is thrown', function() {
Expand All @@ -131,7 +131,7 @@ moduleFor('ember-debug', class extends TestCase {
assert.ok(true, 'deprecations were not thrown');
}

['@test Ember.deprecate does not throw deprecations if second argument is truthy'](assert) {
['@test deprecate does not throw deprecations if second argument is truthy'](assert) {
assert.expect(1);

deprecate('Deprecation is thrown', true, { id: 'test', until: 'forever' });
Expand All @@ -141,23 +141,23 @@ moduleFor('ember-debug', class extends TestCase {
assert.ok(true, 'deprecations were not thrown');
}

['@test Ember.assert throws if second argument is falsy'](assert) {
['@test assert throws if second argument is falsy'](assert) {
assert.expect(3);

assert.throws(() => emberAssert('Assertion is thrown', false));
assert.throws(() => emberAssert('Assertion is thrown', ''));
assert.throws(() => emberAssert('Assertion is thrown', 0));
}

['@test Ember.assert does not throw if second argument is a function'](assert) {
['@test assert does not throw if second argument is a function'](assert) {
assert.expect(1);

emberAssert('Assertion is thrown', () => true);

assert.ok(true, 'assertions were not thrown');
}

['@test Ember.assert does not throw if second argument is falsy'](assert) {
['@test assert does not throw if second argument is falsy'](assert) {
assert.expect(1);

emberAssert('Assertion is thrown', true);
Expand All @@ -167,7 +167,7 @@ moduleFor('ember-debug', class extends TestCase {
assert.ok(true, 'assertions were not thrown');
}

['@test Ember.assert does not throw if second argument is an object'](assert) {
['@test assert does not throw if second argument is an object'](assert) {
assert.expect(1);
let Igor = EmberObject.extend();

Expand All @@ -178,7 +178,7 @@ moduleFor('ember-debug', class extends TestCase {
}


['@test Ember.deprecate does not throw a deprecation at log and silence'](assert) {
['@test deprecate does not throw a deprecation at log and silence'](assert) {
assert.expect(4);
let id = 'ABC';
let until = 'forever';
Expand Down Expand Up @@ -217,7 +217,7 @@ moduleFor('ember-debug', class extends TestCase {
});
}

['@test Ember.deprecate without options triggers a deprecation'](assert) {
['@test deprecate without options triggers a deprecation'](assert) {
assert.expect(4);

registerHandler(function(message) {
Expand All @@ -232,7 +232,7 @@ moduleFor('ember-debug', class extends TestCase {
deprecate('foo', false, { });
}

['@test Ember.deprecate without options triggers an assertion'](assert) {
['@test deprecate without options triggers an assertion'](assert) {
assert.expect(2);
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = false;

Expand All @@ -250,7 +250,7 @@ moduleFor('ember-debug', class extends TestCase {
}


['@test Ember.deprecate without options.id triggers a deprecation'](assert) {
['@test deprecate without options.id triggers a deprecation'](assert) {
assert.expect(2);

registerHandler(function(message) {
Expand All @@ -264,7 +264,7 @@ moduleFor('ember-debug', class extends TestCase {
deprecate('foo', false, { until: 'forever' });
}

['@test Ember.deprecate without options.id triggers an assertion'](assert) {
['@test deprecate without options.id triggers an assertion'](assert) {
assert.expect(1);
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = false;

Expand All @@ -275,7 +275,7 @@ moduleFor('ember-debug', class extends TestCase {
);
}

['@test Ember.deprecate without options.until triggers a deprecation'](assert) {
['@test deprecate without options.until triggers a deprecation'](assert) {
assert.expect(2);

registerHandler(function(message) {
Expand All @@ -289,7 +289,7 @@ moduleFor('ember-debug', class extends TestCase {
deprecate('foo', false, { id: 'test' });
}

['@test Ember.deprecate without options.until triggers an assertion'](assert) {
['@test deprecate without options.until triggers an assertion'](assert) {
assert.expect(1);
ENV._ENABLE_DEPRECATION_OPTIONS_SUPPORT = false;

Expand Down

0 comments on commit ee85052

Please sign in to comment.