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

Issue while updating view Model using setter method #308

Open
Lingareddyvinitha opened this issue Sep 17, 2022 · 1 comment
Open

Issue while updating view Model using setter method #308

Lingareddyvinitha opened this issue Sep 17, 2022 · 1 comment

Comments

@Lingareddyvinitha
Copy link

Lingareddyvinitha commented Sep 17, 2022

Example Code

// STORE
class Todo {
  @observable title = "Test";

  @action.bound
  setTitle(value: string) {
    this.title = value;
  }
}

// CREATE VIEW MODEL
const model = new Todo();
const viewModel = createViewModel(model);

viewModel.setTitle("Updated Test") 
console.log(viewModel.title) // Updated Test
console.log(model.title) // Updated Test

Here when we console the original model we expected title value as "Test" only but actual output is "Updated Test"

package versions:
"mobx": "5.15.0",
"mobx-react": "6.1.4",
"mobx-utils": "5.6.2",

@katsu223
Copy link

@Lingareddyvinitha it is because your setTitle is bound to Todo instance thus updating its title, not viewModel's. Just remove bound

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

No branches or pull requests

2 participants