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

Separates decorator/instance usage of disposeOnUnmount #671

Merged
merged 1 commit into from
Jun 19, 2019
Merged

Separates decorator/instance usage of disposeOnUnmount #671

merged 1 commit into from
Jun 19, 2019

Conversation

JabX
Copy link
Contributor

@JabX JabX commented Apr 24, 2019

Fixes #666 by splitting the disposer store into two separate prototype and instance stores, depending on the target parameter.

@@ -38,9 +34,16 @@ export function disposeOnUnmount(target, propertyKeyOrFunction) {
)
}

// decorator's target is the prototype, so it doesn't have any instance properties like props
const isDecorator = !target.hasOwnProperty("props")

Choose a reason for hiding this comment

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

Very fragile check. What if in future react devs will decide to move props to prototype?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that it isn't the best check ever but I don't know what else we can do to discriminate usage. Also, props is pretty much the one property that will always be tied to the instance (props on the prototype would mean that all instance would share the same props, which completely defeats their purpose), so I think that, even in the future, we're fine making that assumption. Moreover, since classes are pretty much "legacy" now, I doubt anything will change for them in the future, and even if this for whatever reason change, we could still change this check for something else at that (very improbable) moment.

Anyway, now that v6 is out, this PR is pretty much obsolete for me (I had hoped that it could have been merged before) since the new restrictions on the method/decorator are breaking a good chunk of my uses for it. I'll still try to update it when I have the time though

Copy link
Member

Choose a reason for hiding this comment

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

Merging this one now, since it is relevant again after 6.10 :)

Replaced this specificy check with typeof propertyKeyOrFunction === "string", since only when used as decorator we get a string here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my first idea too (and the one I thought about when I wrote the issue), but nothing prevents you to use disposeOnUnmount(this, "myProperty")... though I agree this isn't the way it's supposed to be used.

Anyway thanks a lot for merging the PR!

@danielkcz
Copy link
Contributor

danielkcz commented Jun 8, 2019

@JabX do you want to close this PR if it's not relevant anymore? It should be rebased otherwise.

@danielkcz danielkcz added the has conflicts needs to be merged or rebased label Jun 8, 2019
@mweststrate mweststrate merged commit a9aa100 into mobxjs:master Jun 19, 2019
@mweststrate
Copy link
Member

Releasing as 6.1.1

@mweststrate
Copy link
Member

mweststrate commented Jun 20, 2019 via email

@github-actions github-actions bot mentioned this pull request Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has conflicts needs to be merged or rebased
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixing @disposeOnUnmount and disposeOnUnmount(this, ...) is broken
4 participants