Comments (9)
FYI, PR open that solves this issue.
from delorean.
PR merged, closing this issue. @svdoever - please let us know if you see this on our master branch or future releases. thanks!
from delorean.
happens again.
from delorean.
This will happen if you are dispatching a store action and the action handler does not either this.emit('change')
or use this.set
, which emits a change event automatically. This is because the promise only resolves on a change event. So no change event and the listeners pile up.
from delorean.
Oh okay thank you so much :-) I will have to check a bunch of stores for
this
On Feb 20, 2015 9:13 PM, "Darcy Adams" [email protected] wrote:
This will happen if you are dispatching a store action and the action
handler does not either this.emit('change') or use this.set, which emits
a change event automatically. This is because the promise only resolves on
a change event. So no change event and the listeners pile up.—
Reply to this email directly or view it on GitHub
#20 (comment).
from delorean.
@darcyadams tracking down a leak like this in our code. We have a bunch of event handlers in stores that do some checks and then return without emitting anything if there is no work to be done...
Am I to understand from this that a change event always needs to be emitted?
from delorean.
@tommoor yes, sadly this is currently the state.
The way delorean has been designed form the start (and it took me a bit to realize this) is that a dispatch('action_name')
returns a promise, which is nice. However, in order to resolve that promise, delorean binds to a change
event on the store using .once
. This works great when the store emits
a change event, as the event cleans itself up (by the way, this.set
does this automatically). You run into serious problems pretty quickly, however, if you start dispatching actions that do not result in a change event being fired. If said action gets repeatedly dispatched, you have a pretty serious memory leak on your hands (thankfully node's event emitter module is pretty good at console.warn
ing you when this happens).
Ultimately, delorean needs to handle this behind the scenes. The design I have in mind is to resolve the promise after the action has been dispatched to the store. The primary drawback to this approach is the developer will lose the ability to perform any async work in the store before promise gets resolved. IMO, this is not a big deal, as I keep all my async server interactions in the actions layer, but I'm just not sure if it is a common pattern to peform server (or other async work) inside a store action handler.
Now, the other option would be to ditch the promise based architecture all together. This is actually where I am leaning, but wanted to get sign off from @f when he comes back from his military service. Flux is all about one way data flow, and I do not see a large need for the dispatcher to get a promise back from the store on every action. The store gets and action and takes care of updating the state of it's data, the component reacts to the data changing (or not), and then can trigger new data flows the dispatcher. As soon as you get back a promise from the store, the one way data flow breaks.
from delorean.
@darcyadams thanks for the detailed reply! From the code it looks like as long as some other action on the store emits a change then you're good. This would only be an issue if one action without a change event is emitted many times?
from delorean.
@tommoor yes, once the store emits a change, all promises are resolved and the events cleaned up. The issue is a repeatedly dispatching an action or actions that do not result in change events.
from delorean.
Related Issues (20)
- Lets revive delorean.js! HOT 1
- EventEmitter and Promise missing when using require.js HOT 7
- Please update NPM HOT 12
- set method creates keys on store itself HOT 6
- Will be unavailable for 5 months. HOT 19
- [Bug] StoreListener's can't trigger but can update just fine. HOT 5
- componentWillUpdate prevState HOT 3
- Doesn't work with Require.js HOT 2
- Have scheme work for collections of items HOT 2
- Is delorean dead? HOT 3
- Throw error when attempting to access a store that isn't watched in mixin HOT 2
- JsFiddle example does not work: Object is not a function. HOT 5
- Fiddle linked from README overview is broken HOT 1
- storeListenerMixin can't traverse up to find ancestor's dispatcher HOT 4
- EventEmitter memory leak detected HOT 10
- "You are attempting to create more than one dispatcher." HOT 4
- Tutorial.md HOT 2
- Can't use delorean with requirejs
- Ractive example fix HOT 3
- Expired Project Domain
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 delorean.