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.

Possible to make one-line @Data declarations?

See original GitHub issue

Would 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:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktsncommented, Nov 14, 2016

@HerringtonDarkholme looks good to me 🎉

0reactions
thorningcommented, Nov 16, 2016

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

Read more comments on GitHub >

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

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