mobxjs / mobxjs/mobx-examples

how can i make extendObservable work when i use pojo object?

Open
#10 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
No language data
Stars
286
Forks
31
PR merge metrics
No merged PRs in 30d

Description

Hi i test code like below,but it got undefined,i use latest umd mobx code,thanks for your help,
var Person = function (firstName, lastName, age) {
this.id = .uniqueId('person');
mobx.extendObservable(this, {
firstName: firstName,
lastName: lastName,
age: age,

	fullName:function () {//error code 
		console.count('fullName');
		return this.firstName + ' ' + this.lastName;
	}
});

};

var person = new Person('Matt', 'Ruby', 0);

mobx.autorun(function () {
console.log(person.fullname);//get undefined
});

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the inline constructor and autorun snippet as the reproduction; first compare the observable property declared in extendObservable with the property accessed by autorun. Done means the example runs without an undefined value and produces the intended full-name output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.