Possible to make one-line @Data declarations?
See original GitHub issueWould it be possible to make the @Data decorator work on individual properties?
class TestComponent extends Vue {
normal = 'normal';
@Data test = () => new Test();
@Data own = function () {return this.propValue} //would need this syntax to correctly bind this
@Data shared = () => store.sharedObject
}
I have not worked with decorators before, so don’t know how much is possible. I guess the biggest problem is the type signatures, as this.test needs to be of type Test not () => Test.
Current workaround is to set all data in the data function, and simply declare the variables on the class for typings:
class TestComponent extends Vue {
normal:string;
test:Test;
own:PropType;
shared:SharedObject;
@Data data() {
return {
normal : 'normal',
test : new Test(),
own : this.propValue,
shared : store.sharedObject,
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How can I declare and define multiple variables in one line ...
Careful with those one-line multi-variable declarations. It's easier than you think to declare an int pointer followed by a list of regular integers...
Read more >Assigning multiple variables in one line in Python
Python assigns values from right to left. When assigning multiple variables in a single line, different variable names are provided to the left ......
Read more >Why declare a variable in one line, and assign to it in the next?
In C99 language it is OK to declare variables in the middle of the block (just like in C++), which means that the...
Read more >Chapter 4. Basic Declarations and Expressions - O'Reilly
The basic elements of a program are the data declarations, functions, and comments. Let's see how these can be organized into a simple...
Read more >One line is all you ever need. : r/haskell - Reddit
I challenge you to implement Data.List.sort and Data.Map.Lazy.insert in one line.
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

@HerringtonDarkholme looks good to me 🎉
This looks good to me. So far it have behaved as I intuitively thought it would, including constructors, factory methods and shared stores.