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

5.4.1 Non observed properties are no longer included #205

Closed
timothyallan opened this issue Jun 7, 2019 · 5 comments
Closed

5.4.1 Non observed properties are no longer included #205

timothyallan opened this issue Jun 7, 2019 · 5 comments

Comments

@timothyallan
Copy link

timothyallan commented Jun 7, 2019

So 5.4.1 fixed a previous error for #191 but is causing another. Any properties that aren't marked as observable simply don't appear anymore.

If you cut and paste the below code into the demo sandbox, you'll see what happens. the notObservedField doesn't exist... and in 5.2 it did.

https://codesandbox.io/s/wp88p

import React from "react";
import { render } from "react-dom";
import { observable, action, toJS } from "mobx";
import { observer } from "mobx-react";
import DevTools from "mobx-react-devtools";
import { createViewModel } from 'mobx-utils';

class MyClass {
  @observable firstname;
  @observable lastname;
  notObservedField = 'im not included!';
  someFunction(someParam) {
  }
}

class AppState {
  constructor() {
    const myClass = new MyClass();
    const observableMyClass = createViewModel(myClass);
    console.log(toJS(observableMyClass));
    // is now undefined in 5.4.1
    console.log(observableMyClass.notObservedField);
  }

  @action.bound
  reset() {
    this.timer = 0;
  }
}

const TimerView = observer(({ appState }) => (
  <button onClick={appState.reset}>Seconds passed: {appState.timer}</button>
));


render(
  <div>
    <TimerView appState={new AppState()} />
    <DevTools />
  </div>,
  document.getElementById("root")
);

Edit: I should also mention that this only happened in production builds for me? Dev builds worked fine. Was a bit of a panic after rollover.

@ItamarShDev
Copy link
Member

ItamarShDev commented Jun 10, 2019

notObservedField was not logged also in 5.4.0 and 5.3.0
Am i missing the bugs?

https://codesandbox.io/embed/minimal-mobx-react-project-jh2lz
The latest version I can log the property is in 5.2.0

@timothyallan
Copy link
Author

it worked in 5.2 which was the version we upgraded from.

This is a very breaking change for our app having all those fields just vanish. Shouldn’t it be a major version bump if it’s not a bug?

@urugator
Copy link
Contributor

The getAllMethodsAndProperties seems to be missing the "Properties" part, there are just getters and functions right?

@jasonlangdon-sky
Copy link
Contributor

@urugator right you are. That was an oversight on my behalf as the model I was passing to createViewModel only had observable properties, and no unobserved ones. I'm working on a fix and hope to have it on a branch today.

@mweststrate
Copy link
Member

Published as 5.5.0

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

5 participants