Comments (16)
@brucewpaul 2.0.2
has been published.
Thanks for reporting.
from brcast.
Can you please provide an example?
from brcast.
on the super basic level, if you provide a non function to subscribe, it will throw an error when it is iterating after a setState.
TypeError: listeners[id] is not a function
at Object.keys.forEach.id:10:55
at Array.forEach
at Object.setState:10:28
at eval:36:8
at eval
In our (react) example, we have components that hide/show based on the breakpoint and communicatevia brcast. But if the components are nested, then then the top level component hides it's children, the children functions are no longer present, but brcast still tries to call them, thus throwing an error.
from brcast.
i.e. in the subscribe function, we setState on the react component, but the component is no longer mounted
from brcast.
Object.keys(listeners).forEach(id => typeof listeners[id] === 'function' && listeners[id](_state))
fixed it for me
from brcast.
Uhm I see.
The strange thing is that it should have happened also with previous version no?
You think you can paste the code generating the error?
Or meybe a https://codesandbox.io ?
I'm super curious to see the use case.
from brcast.
this.unsubscribe = this.context[__breakpoint__].subscribe((currentBreakpoint) => {
this.setState({ currentBreakpoint });
});
and in the previous version, it would give a react warning saying that it can't update state on an unmounted component, but this version throws an error
from brcast.
there are a lot of pieces to it, but that is the part that is breaking it. And it only breaks in a nested component described above
from brcast.
not supplying it a function in the precious version also throws an errors, but the react example is throwing an error now
from brcast.
In which lifecycle method are you setting the subscription?
Are you invoking unsubscribe in componentWillUnmount?
If the key exists, I do not understand how the callback function can be undefined.
from brcast.
in componentDidMount
and yes, it is being unsubscribed in componentWillUnmount
from brcast.
So with a higher up component, the breakpoint changes and receives the new breakpoint via brcast causing it to unmount. It also had a child that was subscribed to the same brcast, but is not longer there and unsubscribes as it unmounts. It seems at this point, the key is still in the listeners object and errors when it tries to call it
from brcast.
If you unsubscribe then the listener id should be removed from the keys object as well as the callback.
I'd like to write a test for this.
I can certainly add a quick fix as you proposed but I really want to reproduce the error before with and example or a failing unit test.
Are you willing to help with that?
If it's not too complex perhaps you can create a code sandbox?
Or even better a failing test.
Thanks a lot for reporting this
from brcast.
my pleasure and ya I'd be down to help out. I doubt I'll be able to get something reproducible up today, but will try tomorrow
from brcast.
Sure no problem. Take your time and thanks again
from brcast.
👍
from brcast.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brcast.