npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@reatom/devtools

v0.8.0

Published

Reatom developer tools for states and actions inspecting

Downloads

1,433

Readme

This devtools is NOT coupled to Reatom and may be worked as a general logger for any kind of data. For Reatom users it has some additional features like actions and states cause tracing. But by default it has a huge list of features to log, highlight, filter and inspect any kind of logs.

Installation

npm install @reatom/devtools

Note that this package is published with ESM bundle only.

Setup

Typical setup in your root file may look like that.

declare global {
  var DEVTOOLS: null | Devtools
}
if (import.meta.env.DEV) {
  const { createDevtools } = await import('@reatom/devtools')
  globalThis.DEVTOOLS = createDevtools()
} else {
  globalThis.DEVTOOLS = null
}

It is recommended to put the devtools to the global scope to log and inspect needed data easily during development or debugging.

IMPORTANT NOTE for Reatom users - put your ctx as an option to the create function (createDevtools({ ctx })).

Devtools API

createDevtools returns an object with a few methods:

  • log(name: string, payload?: any) - log any kind of data
  • state<T>(name: string, initState: T): DevtoolsState<T> - log and create a state with a lifetime, which you can update directly later and subscribe to changes from the devtools update form
  • show() - show the devtools (needed for initVisibility: false option)
  • hide() - hide the devtools the opposite to show method :)

With declare global { var DEVTOOLS: undefined | Devtools } you will be able to use this methods like so:

function doSome(payload) {
  DEVTOOLS?.log('doSome', payload)

  // the rest of the code...
}

You can log states too (only changes will be logged)

const [state, setState] = useState()
DEVTOOLS?.state('my-state', state)

With "state" log you can reinit your form from the devtools with the edit tool (see UI features below).

const { values, init } = useForm()
React.useEffect(() => DEVTOOLS?.state('my-form', values).subscribe(init), [state])

createDevtools Options

The create function accepts the following options:

  • initSize?: number - initial value of the size of collected logs
  • initVisibility?: boolean - the predicate to mount the devtools to the DOM, devtools will collect all logs nevertheless of the state, it affects only the UI
  • getColor?: typeof getColor - the function to get the color of the log, the default function available by an import with the same name
  • separator?: string | RegExp | ((name: string) => Array<string>) - the separator to split the name of the log for "state view", . by default
  • privatePrefix?: string - the prefix which mark the log as private, _ by default

UI features

Logs view

Devtools logs view

  1. Filter form - input RegExp will apply to the name of the log immediately, you can choose the type of the match mechanic: equal, not equal, highlight (color picker), off. By pressing "save" button the filter options will be saved in the filters group below.
  2. Filters group - the list of saved filters, which you can change, also additional match mechanic "garbage" can be added, which will throw input logs forever, which is useful for better performance of many logs.

    "private" unremovable filter applies to private logs, which defines by privatePrefix option.

  3. Values search allows you to filter the logs by the stringified payload matching.
  4. Actions allows you to modify the behavior of the devtools:
    • "clear lines" clears causes chain of transactional logs
    • "clear logs" removes all collected logs
    • "size" sets the amount of logs to be collected
    • "inline preview" toggles the preview under log name
    • "hover preview" toggles the preview by document icon before a log name hover
    • "timestamps" toggles the timestamps lines of transactions (you need to restart the page to see the changes)
  5. Log name row starts with chain highlight button, then payload preview button (could be hovered with the options or clicked to hold it), then log name.
  6. Log payload row includes the payload of the log, if the relative option is enabled.
  7. Payload actions (see description below)

Payload inspector view

Devtools payload inspector view

In the screenshot above we turn off the inline preview, clicked at the chain button of "issues.dataAtom" log, which paint the cause chain to other relative logs, and clicked on the document button of "issues.dataAtom" log to see the payload inspector view.

  1. Name of the log (atom) and its payload (state).
  2. List of the changes of this log.
  3. Payload action buttons:
    • Convert to plain JSON (useful for atomized state inspection)
    • Log to the browser console
    • Copy JSON to the clipboard
    • Open edit form (will create additional log if will be applied)
    • Close the inspector