Skip to content

Add better Transition debugging information. - #305

Merged
rwjblue merged 1 commit into
masterfrom
debugging-info
Sep 9, 2020
Merged

rwjblue merged 1 commit into
masterfrom
debugging-info

Conversation

@rwjblue

@rwjblue rwjblue commented Sep 9, 2020

Copy link
Copy Markdown
Member

Expose a few nice debugging tools when working with a transition:

interface Transition {
  /**
    In non-production builds, this function will return the stack that this Transition was
    created within. In production builds, this function will not be present.

    @method debugCreationStack
    @return string
  */
  debugCreationStack?: () => string | undefined;

  /**
    In non-production builds, this function will return the stack that this Transition was
    aborted within (or `undefined` if the Transition has not been aborted yet). In production
    builds, this function will not be present.

    @method debugAbortStack
    @return string
  */
  debugAbortStack?: () => string | undefined;

  /**
    In non-production builds, this property references the Transition that _this_ Transition
    was derived from or `undefined` if this transition did not derive from another. In
    production builds, this property will not be present.

    @property debugPreviousTransition
    @type {Transition | undefined}
  */
  debugPreviousTransition: Maybe<Transition<T>>;
}

Note: I've confirmed that Ember's build pipeline properly replaces the
if (DEBUG) { bits with true and false as appropriate:

if (true
    /* DEBUG */
) {
  var _error = new Error(`Transition creation stack`);

  this.debugCreationStack = () => _error.stack;

  this.debugPreviousTransition = previousTransition;
}

Expose a few nice debugging tools when working with a transition:

```ts
interface Transition {
  /**
    In non-production builds, this function will return the stack that this Transition was
    created within. In production builds, this function will not be present.

    @method debugCreationStack
    @return string
  */
  debugCreationStack?: () => string | undefined;

  /**
    In non-production builds, this function will return the stack that this Transition was
    aborted within (or `undefined` if the Transition has not been aborted yet). In production
    builds, this function will not be present.

    @method debugAbortStack
    @return string
  */
  debugAbortStack?: () => string | undefined;

  /**
    In non-production builds, this property references the Transition that _this_ Transition
    was derived from or `undefined` if this transition did not derive from another. In
    production builds, this property will not be present.

    @Property debugPreviousTransition
    @type {Transition | undefined}
  */
  debugPreviousTransition: Maybe<Transition<T>>;
}
```

---

Note: I've confirmed that Ember's build pipeline properly replaces the
`if (DEBUG) {` bits with `true` and `false` as appropriate:

  ```js
  if (true
      /* DEBUG */
  ) {
    var _error = new Error(`Transition creation stack`);

    this.debugCreationStack = () => _error.stack;

    this.debugPreviousTransition = previousTransition;
  }
```
Comment thread ember-cli-build.js
Comment on lines +49 to +60
[
'babel-plugin-debug-macros',
{
flags: [
{
source: '@glimmer/env',
flags: { DEBUG: isDebug, CI: !!process.env.CI },
},
],
},
'@glimmer/env inlining',
],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this only affects the local tests (not what consumers use). Ember's build pipeline (as well as general Ember apps) uses nearly the same thing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant