Class @ember/debug
assert (desc, test) public
Defined in packages/ember-debug/lib/index.js:69
Available since v1.0.0
import { assert } from '@ember/debug'; |
- desc
- String
- A description of the assertion. This will become the text of the Error thrown if the assertion fails.
- test
- Boolean
- Must be truthy for the assertion to pass. If falsy, an exception will be thrown.
Define an assertion that will throw an exception if the condition is not met.
- In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1 2 3 4 5 6 7 |
import { assert } from '@ember/debug'; // Test for truthiness assert('Must pass a valid object', obj); // Fail unconditionally assert('This code path should never be run'); |
debug (message) public
Defined in packages/ember-debug/lib/index.js:101
import { debug } from '@ember/debug'; |
- message
- String
- A debug message to display.
Display a debug notice.
- In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1 2 3 |
import { debug } from '@ember/debug'; debug('I\'m a debug notice!'); |
registerDeprecationHandler (handler) public
Defined in packages/ember-debug/lib/deprecate.js:14
Available since v2.1.0
import { registerDeprecationHandler } from '@ember/debug'; |
- handler
- Function
- A function to handle deprecation calls.
Allows for runtime registration of handler functions that override the default deprecation behavior. Deprecations are invoked by calls to Ember.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.
1 2 3 4 5 6 7 8 |
Ember.Debug.registerDeprecationHandler((message, options, next) => { if (message.indexOf('should') !== -1) { throw new Error(`Deprecation message with should: ${message}`); } else { // defer to whatever handler was registered before this one next(message, options); } }); |
The handler function takes the following arguments:
-
message
- The message received from the deprecation call. -
options
- An object passed in with the deprecation call containing additional information including: -
id
- An id of the deprecation in the form ofpackage-name.specific-deprecation
. -
until
- The Ember version number the feature and deprecation will be removed in. -
next
- A function that calls into the previously registered handler.
registerWarnHandler (handler) public
Defined in packages/ember-debug/lib/warn.js:16
Available since v2.1.0
import { registerWarnHandler } from '@ember/debug'; |
- handler
- Function
- A function to handle warnings.
Allows for runtime registration of handler functions that override the default warning behavior. Warnings are invoked by calls made to warn. The following example demonstrates its usage by registering a handler that does nothing overriding Ember's default warning behavior.
1 2 3 4 |
import { registerWarnHandler } from '@ember/debug'; // next is not called, so no warnings get the default behavior registerWarnHandler(() => {}); |
The handler function takes the following arguments:
-
message
- The message received from the warn call. -
options
- An object passed in with the warn call containing additional information including: -
id
- An id of the warning in the form ofpackage-name.specific-warning
. -
next
- A function that calls into the previously registered handler.
runInDebug (func) public
Defined in packages/ember-debug/lib/index.js:183
Available since v1.5.0
import { runInDebug } from '@ember/debug'; |
- func
- Function
- The function to be executed.
Run a function meant for debugging.
- In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.
1 2 3 4 5 6 7 8 9 10 |
import Component from '@ember/component'; import { runInDebug } from '@ember/debug'; runInDebug(() => { Component.reopen({ didInsertElement() { console.log("I'm happy"); } }); }); |
warn (message, test, options) public
Defined in packages/ember-debug/lib/warn.js:63
Available since v1.0.0
import { warn } from '@ember/debug'; |
- message
- String
- A warning to display.
- test
- Boolean
- An optional boolean. If falsy, the warning will be displayed.
- options
- Object
- An object that can be used to pass a unique `id` for this warning. The `id` can be used by Ember debugging tools to change the behavior (raise, log, or silence) for that specific warning. The `id` should be namespaced by dots, e.g. "ember-debug.feature-flag-with-features-stripped"
Display a warning with the provided message.
- In a production build, this method is defined as an empty function (NOP). Uses of this method in Ember itself are stripped from the ember.prod.js build.