0.1.1 • Published 3 months ago

rxjs-browser-debugger v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

RXJS browser debugger

RXJS browser debugger is a debug tool that visualizes rxjs observable emissions and other events in a marble diagram.

Requirements

  • As the name suggests, the tool only works when the code is executed in a browser. It does not work in a server environment.
  • The tool opens a pop-up window, so the browser should be configured not to block them.
  • rxjs must be version 7.3.0 or higher.

Installation

npm install --save-dev rxjs-browser-debugger

Getting started

To track emissions and other events, use the debug operator in an observable pipe:

import { debug } from 'rxjs-browser-debugger';

target$ = source$.pipe(
  debug('before map'),
  map(x => 2*x)
);

This creates a debug observer that registers all emissions and other events that occur right before the map operator. When target$ has been subscribed to, a pop-up window will open showing the marble diagram of the debug observer.

The debug operator

syntax

  • debug()
  • debug(description)
  • debug(description, shouldDebug)

description: string

Default value: ''

A description to be used for the debug observer. Although optional, it is highly recommended to set this, so that it is immediately clear where emissions and other events originate from.

shouldDebug: (subscriptionIndex: number) => boolean

Default value: () => true

A function that returns a boolean whether a subscription should be added to the marble diagram. This function takes the subscription index as parameter, which starts with 0 and increments after every new subscription. This parameter is useful to control what subscriptions should be included in the marble diagram.

The debug tool application window

Opening the window

The debug window will be opened in the following situations 1. When any debug observer registers an emission or other event. 2. When openRxjsBrowserDebugger() is executed in the browser console. Note that the debug operator must be imported at least once in order for this to work.

Explanation of the window

Screenshot with numbers

  1. Menu to configure how the debug observers should be sorted.
  2. Filter menu. This menu is only visible when the user hides a debug observer (see 5) and can be used to show the debug observer again.
  3. Recording button. Click to toggle between pause and record. When paused, emissions and other events will not be recorded and thus not be displayed in the marble diagram. Warning: this also means that emissions and other events will not cause to open the window if it has been closed later. To open the window, openRxjsBrowserDebugger() must be executed in the browser console as explained earlier.
  4. Clear button that clears all emissions and other events visible in the marble diagram and hidden in the filter.
  5. Information about the debug observer. Top title contains the description provided in the debug operator. The debug observers and their tracked subscriptions are numbered. The label on the bottom-left can be clicked to hide the debug observer from view. It can be shown again using the filter menu (see 2). The icon on the bottom-right indicates the status of the subscription (pending, complete, error, or unsubscribed).
  6. Marble indicating an error. Hover to see tooltip with error message if applicable. Click to log the error to the console of the parent window.
  7. Marble indicating a subscription.
  8. Marbles indicating an emitted value. Hover to see tooltip with string value. Click to log the value to the console of the parent window.
  9. Marble indicating a completion.
  10. Marble indicating an unsubscription.

Note: all marbles are ordered in time from left to right. Emissions and other events that are immediately scheduled from each other, either synchronously or asynchronously, are grouped together.

License

Copyright 2024, Kevin Choi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.