Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Shorthand for computed with getter/setter pattern #1196

Closed
maxdeviant opened this issue Oct 9, 2017 · 2 comments
Closed

[RFC] Shorthand for computed with getter/setter pattern #1196

maxdeviant opened this issue Oct 9, 2017 · 2 comments

Comments

@maxdeviant
Copy link

A pattern that I find myself using quite often is something like this:

class Todo {
  @observable private _name = '';

  @computed
  get name() {
    return this._name;
  }

  set name(value) {
    this._name = value;
  }
}

Now, this is a lot of boilerplate for something that could be as simple as:

class Todo {
  // Open to suggestions for what we would call this :)
  @autoComputed name = '';
}

I find that this pattern is useful when working with domain objects (in strict mode), since I can tweak the properties anywhere without needing to introduce an action everytime I wish to do so.

@mweststrate What are your thoughts on adding something like this? Or have I invented a solution for a problem that I created myself (like perhaps using strict mode where it isn't actually useful/needed)? 😄

@urugator
Copy link
Collaborator

urugator commented Oct 9, 2017

Discussed in #839, also check https://github.com/farwayer/mobx-decorators#setter

@mweststrate
Copy link
Member

Closing for duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants