3 ms·
I don't know much about React. When poking through the code I found this: https://github.com/benoitvallon/react-native-nw-react-calculator/blob/master/src/comm
by ridiculous_fish 11y ago
I don't know much about React. When poking through the code I found this:
https://github.com/benoitvallon/react-native-nw-react-calculator/blob/master/src/common/stores/CalculatorStore.js https://github.com/benoitvallon/react-native-nw-react-calcul...
Lots of ad-hoc global variables like _lastPressedWasEqual. Is this idiomatic?
- CGamesPlay 11y agoThey aren't global, they're local to the source file, which represents a singleton class, so it's not really dangerous. You could think of them as static variables in a singleton class.
- cballard 11y ago> You could think of them as static variables in a singleton class. So... global variables?
- ridiculous_fish 11y agoI'm not sure what justifies using a Singleton here - what if I want more than one Calculator in my app? I also noticed that we have a Store (which I interpret to mean model-layer) handling key events, e.g. "processBackKeyPressed()". Is that common too? From my outsider's perspective, this looks like a layering violation.
- CGamesPlay 11y agoI didn't write this so I am not in a good place to argue in favor or against any pattern, but the obvious answer here would be the needs of the application justify a Singleton. The app doesn't support more than one Calculator, adding additional object management for a feature that isn't necessary is strictly wasted effort. I don't think it's a "key event" in the sense you're imagining. The store is a black box around a calculator device with emulated physical buttons, so "back key pressed" is one of the store's fundamental actions. I might be wrong about this.
- ravishi 11y agoApparently, that's how people build "flux stores" in samples. Their purpose is to hold "all the state of the application", so that design is enough. I'm not versed in Flux, but I can imagine that in real world situations one would actually build a store that has some sort of persistent cache, like by using a database or the filesystem.