Extract decorated functions as top level variables
See original GitHub issueCould we get an option in .babelrc
to extract each decorated function individually as it’s own variable. Reason being is that react-hot-loader requires the OG decorated function (react component) to be its own top level variable. See their docs for the full explanation.
Currently this plugin transforms decorators to something like this:
const SuperComponent =
connect()( <-- last HoC
withSomeStuff( <-- first HoC
Component <-- a real component
)
);
But with a "topLevel": true
plugin option in .babelrc
(just in development env section in my case), this plugin could transform decorators like this:
const WithSomeStuffComponent = withSomeStuff(Component);
const SuperComponent = connect()(WithSomeStuffComponent);
Would this be possible?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Can a decorated function access variables of the decorator
Because of Python's scoping rules, a decorated function generally can't access any variables in the decorator. However, since functions can ...
Read more >Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >A Deep Dive into Python Decorators - Deepnote
In more details, decorators are just functions that take another function as an argument and have wrapped inner function that can use arguments ......
Read more >5 Advanced Tips on Python Decorators | by Michael Berk
1 — What's a decorator? Before we get into the tips, let's cover how decorators work. Decorators are simply functions that take a...
Read more >Decorators with parameters in Python - GeeksforGeeks
In this article, we will learn about the Decorators with Parameters with help of multiple examples. Python functions are First Class ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this is exactly what I’m attempting here 😃,
https://www.npmjs.com/package/babel-plugin-undecorate
I’m assuming the reason you’d want this is for testability of the underlying class/method (that’s why I wanted it).
OK, reopening to be looked at by @loganfsmyth