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

@action get func(){} should have a more accurate error message. #971

Closed
3 of 4 tasks
leedstyh opened this issue Apr 28, 2017 · 3 comments
Closed
3 of 4 tasks

@action get func(){} should have a more accurate error message. #971

leedstyh opened this issue Apr 28, 2017 · 3 comments

Comments

@leedstyh
Copy link

leedstyh commented Apr 28, 2017

I have a*:

  1. Idea:
  • What problem would it solve for you?
  • Do you think others will benefit from this change as well and it should in core package (see also mobx-utils)?
  • Are you willing to (attempt) a PR yourself?

This is my stupid mistake, but figure it out take me a lot time.

export const BadStore = new class {
	@observable Text = "" // Text = observable("")

	@action get String() { // stupid mistake here, should not have a `get`
		//
	}

	@action Update(s) {
		this.Text = s
	}
}

autorun(()=>{
	console.log(BadStore.Text)
})

BadStore.Update("hello")

My bad that did not notice the grammar mistake, but I got these error message in the console:

mobx.js:1345 [mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[Autorun@3] TypeError: Object.defineProperty called on non-object
    at Function.defineProperty (<anonymous>)
    at classPropertyDecorator (/js/app.bundle.js:23322:24)
    at /js/app.bundle.js:23355:64
    at /js/app.bundle.js:20790:43
    at action (/js/app.bundle.js:20771:39)
    at /js/app.bundle.js:20750:25
    at /js/app.bundle.js:23332:17
    at /js/app.bundle.js:23371:122
    at Array.forEach (native)
    at runLazyInitializers (/js/app.bundle.js:23371:82)

The error message did not point me to the real error place. So i did some search. And I changed @observable Text = "" to Text = observable(""). It solved, no error message now.

But this confused me more. It should not be fix like this. Finally I find the mistake.

So I think a more accurate error message here would be very helpful.

YuriiOstapchuk added a commit to YuriiOstapchuk/mobx that referenced this issue Apr 29, 2017
@mweststrate
Copy link
Member

mweststrate commented Jun 8, 2017

@YuriiOstapchuk did you intend to create a PR for the above?

@YuriiOstapchuk
Copy link

@mweststrate I indeed intended to, but looks like I broke something else.

@mweststrate
Copy link
Member

PR was merged and released as part of 3.3.0

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

3 participants