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

mobx-preact-devtools

v0.0.19

Published

Dev-tools for MobX and Preact

Downloads

5

Readme

mobx-preact-devtools (in developing)

DevTools for MobX to track the rendering behavior and data dependencies of your app.

It is a fork from original react mobx devtools (https://github.com/mobxjs/mobx-react-devtools) to work with preact instead of react.

MobX DevTools

Installation

npm install --save-dev mobx-preact-devtools

Usage

Somewhere in your application, create a DevTools component:

import { h, Component } from 'preact';
import DevTools from 'mobx-preact-devtools';

class MyApp extends Component {
  render() {
    return (
      <div>
        ...
        <DevTools />
      </div>
    );
  }
}

Supported props:

  • highlightTimeout — number, default: 1500
  • noPanel — boolean, if set, do not render control panel
  • position — object, position of control panel, default: { top: -2, right: 20 }
  • className — string, className of control panel
  • style — object, inline style object of control panel
  • position — string or object, topRight, bottomRight, bottomLeft or topLeft, default: bottomRight

The position of the panel can be tweaked by setting the value to an object with top, right, bottom or left defined. Setting it to { top: -2, right: 20 } is the same as topRight.

From there on, after each rendering a reactive components logs the following three metrics:

  1. Number of times the component did render so far
  2. The time spend in the render() method of a component
  3. The time spend from the start of the render() method until the changes are flushed to the DOM

For each component the color indicates roughly how long the coloring took. Rendering times are cumulative; they include time spend in the children

  • Green: less then 25 ms
  • Orange: less then 100 ms
  • Red: rendering for this component took more than 100ms

About log groups

Note that if logging is enabled, MobX actions and reactions will appear as collapsible groups inside the browsers console. Mind that any log statements that are printed during these (re)actions will appear inside those groups as well, so that you can exactly trace when they are triggered.

Configuration

import { configureDevtool } from 'mobx-preact-devtools';

// Any configurations are optional
configureDevtool({
  // Turn on logging changes button programmatically:
  logEnabled: true,
  // Turn off displaying components updates button programmatically:
  updatesEnabled: false,
  // Log only changes of type `reaction`
  // (only affects top-level messages in console, not inside groups)
  logFilter: change => change.type === 'reaction',
});

There are also aliases for turning on/off devtools buttons:

import { setLogEnabled, setUpdatesEnabled, setGraphEnabled } from 'mobx-preact-devtools';

setLogEnabled(true); // same as configureDevtool({ logEnabled: true });
setUpdatesEnabled(false); // same as configureDevtool({ updatesEnabled: false });
setGraphEnabled(false); // same as configureDevtool({ graphEnabled: false });

Custom panel design

import { h, Component } from 'preact';
import DevTools, { GraphControl, LogControl, UpdatesControl } from 'mobx-preact-devtools';

class MyNiceButton extends Component {
  render() {
    const { active, onToggle, children } = this.props;
    return (
      <button onClick={onToggle}>
        {children}
        {active ? ' on' : ' off'}
      </button>
    );
  }
}

class MyApp extends Component {
  render() {
    return (
      <div>

        {/* Include somewhere with `noPanel` prop. Is needed to display updates and modals */}
        <DevTools noPanel />

        <div className="my-custom-devtools-panel-design">
          <GraphControl>
            {/* Must have only one child that takes props: `active` (bool), `onToggle` (func) */}
            <MyNiceButton>Graph</MyNiceButton>
          </GraphControl>
          <LogControl>
            {/* Must have only one child that takes props: `active` (bool), `onToggle` (func) */}
            <MyNiceButton>Log</MyNiceButton>
          </LogControl>
          <UpdatesControl>
            {/* Must have only one child that takes props: `active` (bool), `onToggle` (func) */}
            <MyNiceButton>Updates</MyNiceButton>
          </UpdatesControl>
        </div>
      </div>
    );
  }
}

Changelog

0.0.1 Changed Readme, package.json and remote git repo

0.0.2 Migrated to preact from react, added babel plugin and preset for preact

0.0.3 updated Readme

0.0.5 removed prop-types, because they are compatible with preact

0.0.6 removed all mobx-react dev dependencies

0.0.7 removed React in UpdatedControl.jsx

0.0.8 removed cloneElement method from react library

0.0.9 moved PanelButton to main components: LogControl, GraphControl and UpdatesControl