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

TypeError when an interception is removed in intercept #1950

Closed
danrot opened this issue Apr 23, 2019 · 1 comment · Fixed by #2157
Closed

TypeError when an interception is removed in intercept #1950

danrot opened this issue Apr 23, 2019 · 1 comment · Fixed by #2157
Labels

Comments

@danrot
Copy link

danrot commented Apr 23, 2019

I have created an interception using the intercept function and called another function inside, which removes another interception on the same locale. This looks something like this:

intercept(this.locale, '', (change) => {
    this.listStore.destroy();
    return change;
});

The destroy method of the listStore removes an interception on the this.locale reference. And this seems to happen during MobX iterates over all the interceptions, which finally results in the following error:

Uncaught TypeError: interceptors[i] is not a function
    at interceptChange$$1 (mobx.module.js?8b18:2802)
    at ObservableValue$$1.prepareNewValue (mobx.module.js?8b18:774)
    at ObservableValue$$1.set (mobx.module.js?8b18:755)
    at ResourceStore.setLocale (ResourceStore.js?1b9b:108)
    at executeAction$$1 (mobx.module.js?8b18:649)
    at ResourceStore.res (mobx.module.js?8b18:640)
    at Object.onChange (MediaDetails.js?013a:193)
    at Object.Select._this.handleOptionClick [as onOptionClick] (Select.js?f6a9:56)
    at OptionList._this.handleOptionClick (OptionList.js?7462:23)
    at Option._this.handleOnClick (Option.js?f8b9:24)

This makes totally sense, once you got your head around it, but it took me some time and debugging to get there. I know that removing stuff from a collection while iterating over it is a very common problem, and could totally understand if you say that it should not be supported. However, the error was not very helpful, so I would at least expect an error saying that disposing interceptions in an interception is not supported.

Or, if there is no reason to not support it, I found this stackoverflow answer describing a solution. I could also imagine to provide a PR implementing that, since it does not seem a change that hard.

@lock
Copy link

lock bot commented Dec 15, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants