reflux / refluxjs

A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
BSD 3-Clause "New" or "Revised" License
5.36k stars 330 forks source link

Reflux.Component with no store. #509

Closed leny closed 7 years ago

leny commented 7 years ago

Hi,

I'm not really sure this is really a bug ; in a big project with React + Reflux, I've created a base component from which all my components inherits.

class BaseComponent extends Reflux.Component { … }

All works OK until I create a component with no store to listen to. By design, reflux is allowing this. But when the component calls its componentWillUnmount method, an Error is thrown because the property __storeunsubscribes__ isn't an Array (which breaks the for loop code here).

The bug can be handled by adding a simple this.stores = []; in my base component, but I think this is probably a bug that we can address here in Reflux : if we can define a Reflux.Component with no store, the componentWillUnmount method is broken (I can send a PR to fix that) ; if we can't define a Reflux.Component with no store, maybe we should raise an error or a warning?

Thanks,

BryanGrezeszak commented 7 years ago

It is very much intentional to allow one without a store attached, because that's how mapStoreToState works (it's totally separate from the this.store concept).

So yes, definitely a bug. And an easy fix, so thanks for pointing it out. I'll have it fixed in the next update.

leny commented 7 years ago

Ok. Do you want me to submit a PR for that?

BryanGrezeszak commented 7 years ago

@leny - don't worry about it. I already got it fixed and will push the fix live soon.

BryanGrezeszak commented 7 years ago

Should now be fixed as of v6.1.0, which is now published on here, bower, npm, etc.