DanWahlin / Observable-Store

Observable Store provides a simple way to manage state in Angular, React, Vue.js and other front-end applications.
MIT License
638 stars 121 forks source link

Added IsStoreInitialized static function to the Observable Store #285

Closed JasonLandbridge closed 1 year ago

JasonLandbridge commented 1 year ago

There are situations where it might be useful to check if the store state has already been initialised. Currently I ran into this problem when creating unit tests for individual services where I would like (maybe not smart?) to let those services initialise the state when it hasn't happened yet.

JasonLandbridge commented 1 year ago

I see my IDE messed up the formatting, fixing now

JasonLandbridge commented 1 year ago

@DanWahlin If you're okay with this change, would you maybe prefer a static getter or is a static function fine?

DanWahlin commented 1 year ago

Thanks @JasonLandbridge! Appreciate the contribution. I haven't run across this particular scenario but I think having that type of information about the state is useful. It still keeps things simple which is my overall goal for the library.

As far as function versus getter, as I was looking through the PR I wondered about that as well. I'd lean toward the getter since the existing functions are all actions (getXX, setXX, dispatchXX, resetXX, etc.).

JasonLandbridge commented 1 year ago

My pleasure, I in turn appreciate this awesome library! I agree and have changed it to a static getter and changed the ReadMe accordingly. I did keep the IsStoreInitialized name since it returns a boolean

DanWahlin commented 1 year ago

Thanks! I'll try to get the new version published as soon as I have a chance.

JasonLandbridge commented 1 year ago

Awesome, thanks! No rush!

DanWahlin commented 1 year ago

Updated to 2.2.15 as a heads-up. Thanks again!