Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better Transition debugging information. #305

Merged
merged 1 commit into from
Sep 9, 2020
Merged

Conversation

rwjblue
Copy link
Collaborator

@rwjblue rwjblue commented Sep 9, 2020

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 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
Collaborator 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