
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
babel-plugin-mobx-observer-on-every-react-component
Advanced tools
Wrap literally every React component in an MobX observer higher order component.
This plugin will wrap literally every React component in a MobX observer higher order component.
When using MobX, MobX-State-Tree, or any other library in the MobX ecosystem, you may find yourself in one of two scenarios:
observer
from mobx-react
or @observer
from mobx-react-lite
in every single file and wrap your components. This is something that seems to come up again and again.The typical recommendation from MobX is to just use the @observer
decorator or the observer
HOC and accept that you'll have to import it and use it in every file. This plugin doesn't actually change that requirement, it just makes it so that you don't have to manually do that. You may find value in this plugin if you either hate having to remember that, or if you just don't like the way it looks.
Not that we have evidence for. The MobX docs specifically recommend wrapping every component in an observer, saying:
observer only enhances the component you are decorating, not the components called by it. So usually all your components should be wrapped by observer. Don't worry, this is not inefficient. On the contrary, more observer components make rendering more efficient as updates become more fine-grained.
We don't actually have benchmarks to share, so it's always possible there's some small cost, but it's likely to be negligible. If you disagree, send us some benchmarks and we'll update this section!
# npm
npm install --save-dev babel-plugin-mobx-observer-on-every-react-component
# yarn
yarn add --dev babel-plugin-mobx-observer-on-every-react-component
# pnpm
pnpm add --dev babel-plugin-mobx-observer-on-every-react-component
# bun
bun add --dev babel-plugin-mobx-observer-on-every-react-component
Add the plugin to your .babelrc
file:
{
"plugins": [
["babel-plugin-mobx-observer-on-every-react-component"]
]
}
If you prefer using a JavaScript configuration file, you can add the plugin to your babel.config.js
:
module.exports = function(api) {
api.cache(true);
return {
plugins: [
'babel-plugin-mobx-observer-on-every-react-component'
]
};
};
You can pass an optional object to the plugin to configure the behavior of the plugin. Options look like this:
/**
* Options for the plugin
*/
interface PluginOptions {
// Default false, controls if we log debug statements during plugin execution. Mostly intended for plugin developers.
debugEnabled?: boolean;
}
Here are some options we'll eventually add:
Coming soon: eventually we'll have a syntax to ignore entire files or lines of code if you prefer to opt-out of plugin transformation.
cd example
bun install
bun dev
Then check out the Vite app that starts.
You can see the plugin in action with different starting points using the Babel REPL. This is also a great way to provide us with reproducible examples for bug reports.
We'd love to have any help. Please open an issue or discussion if you want to get started.
Here are some resources we've used to learn how to develop Babel plugins:
We use Bun for package management, running tests, and building the project (sort of - we are actually using tsc under the hood with Bun as a task runner for this).
bun install
bun test
cd example && bun install
bun dev
to start the dev server and see a Vite app that points to a local build of this package.bun run build
in the root of the project and restart the dev server in the example folder.bun run build
in the root of the project.FAQs
Wrap literally every React component in an MobX observer higher order component.
The npm package babel-plugin-mobx-observer-on-every-react-component receives a total of 5 weekly downloads. As such, babel-plugin-mobx-observer-on-every-react-component popularity was classified as not popular.
We found that babel-plugin-mobx-observer-on-every-react-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.