reflux / reflux-core

A simple core library for uni-directional dataflow application architecture inspired by ReactJS Flux
BSD 3-Clause "New" or "Revised" License
48 stars 19 forks source link

Error is thrown depending on order when listeners are registered #12

Closed spoike closed 8 years ago

spoike commented 9 years ago

Need to verify if reflux/refluxjs#38 is working or not.

The following error is produced in certain configurations on this line:

Uncaught TypeError: Cannot read property 'hasListener' of undefined

This happens when you register composed listeners before other stores and actions. The args array has a length set, but is an array of undefined.

Testcase pseudo code:

// Inside a store init
var join = Reflux.all(testAction1, testAction2);

this.listenTo(join, resetCallback);
this.listenTo(testAction2, commonlyCalledCallback); // throws the error from here

Workaround is to listen to the joined actions/stores afterwards:

this.listenTo(testAction2, commonlyCalledCallback);
this.listenTo(join, resetCallback);
// no errors thrown, works as expected
devinivy commented 8 years ago

This appears to be fixed: https://github.com/reflux/reflux-core/blob/3e7c9d816a504a1f6dd12337840ad589f5bfc874/test/composedListenable.spec.js#L182-L202

In case there's still any doubt around its usage with createStore(), this also passes: https://github.com/devinivy/reflux-core/commit/cce2e4d8352bd65ddd7ac37c4313691f7e31d4e1

spoike commented 8 years ago

Thanks @devinivy. Is it okay for me to pull in your commit?

devinivy commented 8 years ago

Go for it! Made a PR https://github.com/reflux/reflux-core/pull/18

devinivy commented 8 years ago

That test was pulled-in to master. Seems this is fixed :+1: