Skip to content
This repository was archived by the owner on Dec 31, 2020. It is now read-only.

Issue #839: Re-add isMobXReactObserver property and perform check on class components#843

Merged
danielkcz merged 8 commits into
mobxjs:masterfrom
ynejati:ismobxreactobserver
May 6, 2020
Merged

Issue #839: Re-add isMobXReactObserver property and perform check on class components#843
danielkcz merged 8 commits into
mobxjs:masterfrom
ynejati:ismobxreactobserver

Conversation

@ynejati
Copy link
Copy Markdown
Contributor

@ynejati ynejati commented Feb 28, 2020

Fixes #839

  • Added/updated unit tests
  • Updated changelog
  • Updated README if applicable

@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented Feb 28, 2020

Updated the change log. Going to need to actually increment the version, potentially add tests, and update the Readme. Looking for guidance on what you'd like me to do. Should have marked it as a draft PR, but can't backtrack, so going to mark as WIP for now.

@ynejati ynejati changed the title Issue #839: Re-add isMobXReactObserver property and perform check on … Issue #839: Re-add isMobXReactObserver property and perform check on class components. [WIP] Feb 28, 2020
@danielkcz
Copy link
Copy Markdown
Contributor

danielkcz commented Feb 28, 2020

Do not need to bump version, will happen in a release process.

I would probably wrap both of those code blocks to __DEV__ check as we don't this in production.

Adding test good idea for sure and to tweak the on that is broken as well.

Also thinking it might better to use Symbol instead of string property.

@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented Feb 28, 2020 via email

@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented Feb 29, 2020

Okay, I see now. Regarding a subclass who extends a parent class and overrides the parents reactive render. This behavior is not supported. The subclass will need to re-declare itself as an observer. That is fair. Curious, what happens to the reaction of the parent class. Is it leaked?

Copy link
Copy Markdown
Contributor

@danielkcz danielkcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better, although I am still not happy that functional components won't have this check. I would like to see it unified.

Comment thread src/observerClass.ts Outdated
Comment thread src/observerClass.ts Outdated
@ynejati ynejati changed the title Issue #839: Re-add isMobXReactObserver property and perform check on class components. [WIP] Issue #839: Re-add isMobXReactObserver property and perform check on class components Mar 28, 2020
@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented Mar 28, 2020

Decided to keep it simple, and just log a warning instead of performing some hand holding. I haven't heard anyone else complain about the removal of the isMobxReactObserver string property, so we went with symbol/string util. Going to do a similar check in the lite lib next.

Comment thread src/observerClass.ts Outdated
@danielkcz
Copy link
Copy Markdown
Contributor

@ynejati Are you willing to continue on this PR?

@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented Apr 28, 2020

@FredyC, yep. Sorry, been MIA. These last couple of months have been weird.

@ynejati ynejati force-pushed the ismobxreactobserver branch from 51c87dd to ab88a4e Compare April 28, 2020 12:33
@danielkcz
Copy link
Copy Markdown
Contributor

Please update the size limit config to 4.1 kB. Also, some tests are failing.

@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented Apr 29, 2020

Bummer. Okay.

@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented May 2, 2020

I'll fix the tests, but just so you know they are also broken on the master.

@danielkcz
Copy link
Copy Markdown
Contributor

danielkcz commented May 2, 2020

Oh! That's interesting. For a while, I thought it's some failure on Coveralls side. Only now when I saw failed test-size I checked the other one too.

If you have time for it I would certainly appreciate if you can fix those. I believe it's merely about import the observer batching, probably best to do that in jest.setup.ts.

- Update mobx-react-lite dependency version
- Import observer batching in jest setup config
@ynejati ynejati force-pushed the ismobxreactobserver branch from ab88a4e to 3f6a121 Compare May 2, 2020 13:30
@ynejati
Copy link
Copy Markdown
Contributor Author

ynejati commented May 5, 2020

@FredyC, this thing is ready when you get a chance. Thanks, man.

Copy link
Copy Markdown
Contributor

@danielkcz danielkcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just one last change, please.

Comment thread package.json Outdated
@danielkcz danielkcz merged commit 376bff7 into mobxjs:master May 6, 2020
@danielkcz
Copy link
Copy Markdown
Contributor

Thanks a lot, that was somewhat painful PR given how little it is :)

Comment thread src/observerClass.ts
const target = componentClass.prototype

if (componentClass[mobxObserverProperty]) {
const displayName = getDisplayName(this)
Copy link
Copy Markdown
Contributor

@danielkcz danielkcz Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ynejati Looks like the issue #887 is related to this change. What is the idea behind using this in here? It's going to be undefined every time.

Copy link
Copy Markdown
Member

@mweststrate mweststrate Jul 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be correct, as this isn't bound at this (lol) point, I think componentClass.displayName || componentClass.name will do the trick here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Javascript "strict" mode this will die hard iirc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's silly. Surprised that it's taken this long to catch it. How embarrassing. I guess the test failed to catch it as well. I will submit a PR later today if someone doesn't get to it before me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target seems to work too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test output before (using this):

image

Test output after (using target):

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-add isMobXReactObserver property on class components

3 participants