decorator around mixins
See original GitHub issueI saw the deprecation warnings for using mixins are reverted with 0.13.3
, so the official story is now to use mixins, always. I think it’d be nice to also support ES6 classes and not force everyone to use mixins in their code if they’d prefer not to.
I came up with a first draft on how it could be implemented by reusing the mixin internally and exposing a decorator function.
https://jsfiddle.net/ksmth/t34ak1q3/10/
// ES7
@routerState
class MyComopnent extends React.Component {
// ...
}
// ES6
class MyComopnent extends React.Component {
// ...
}
MyComopnent = routerState(MyComopnent);
// React.createClass without mixins
var MyComopnent = React.createClass({
// ...
});
MyComopnent = routerState(MyComopnent);
Issue Analytics
- State:
- Created 8 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
What is the difference between a mixin and the decorator ...
A mixin is apt when you're adding some behavior to your class. ... A decorator on the other hand is more of a...
Read more >Decorators and Mixins in Lightning Web Components
In essence, a decorator is a function that can modify a class, or any of its properties and methods.
Read more >Enhancing Mixins with Decorator Functions - Justin Fagnani
Adding instanceof support and mixin caching to subclass factories with mixin decorator functions.
Read more >Decorators and Mixins in Lightning Web Components - DZone
In essence, a decorator is a function that can modify a class, or any of its properties and methods.
Read more >Decorators and Mixins – Cross-cutting Aspects
Chapter 8. Decorators and Mixins – Cross-cutting Aspects. A software design often has aspects that apply across several classes, functions, or methods.
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 Free
Top 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
I think @taurose makes a good point about the breaking refs and animations. HoC might solve one problem, but it could cause more problems as well. Is the best way to access the router methods for an ES6 class is through the contextType class property?
Then to access router methods, this.context.router.[method]
Thanks for sharing 👍
I wonder if it wouldn’t be preferable to use class inheritance though, in order to avoid the extra wrapper component which breaks refs and animations.
Something like