question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extract decorated functions as top level variables

See original GitHub issue

Could 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:open
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sirrodgepodgecommented, Jul 1, 2018

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).

0reactions
danboveycommented, Jul 5, 2018

OK, reopening to be looked at by @loganfsmyth

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found