Questions tagged [state]
The State pattern is used to represent the internal state of an object and to encapsulate varying behavior for the same object based on its state. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and thus improve maintainability.
76 questions
1
vote
1
answer
111
views
Is this how Flutter BloC is suppose to be used?
I'm new to Flutter and BloC and it just seems quite different than what I've been using until now. In terms of state, I'm coming from the JS world of Vuex, Pinia and Redux and I've also worked a with ...
5
votes
1
answer
546
views
Better way to share JavaScript code [closed]
I am working on a website using .NET Razor Pages. I have multiple pages that share JavaScript code. I'm using vanilla JavaScript. I have to perform actions related to mapping using leaflet. Most of ...
3
votes
1
answer
132
views
Type-state pattern and state management for credentials struct used with Spotify web API
I am implementing authentication with the Spotify web API as part of a larger project. Yes I know there are already crates that can handle it for me but that is no fun. I am implementing the auth code ...
6
votes
3
answers
978
views
A chess engine in Java: generating white pawn moves - take II
Intro
This post continues the A chess engine in Java: generating white pawn moves.
I was advised to choose between efficiency and type safety. Since this is my first attempt at a chess engine, I have ...
9
votes
4
answers
2k
views
A chess engine in Java: generating white pawn moves
(This post has now a continuation.)
I decided to embark on implementing my own chess engine. The first (and perhaps most demanding) part of that endeavour is generating child states out of a given ...
2
votes
1
answer
143
views
How to manage array of states effectively?
I have a working code to have 2 search bars with dropdown suggestions, selectable by both mouse and arrow keys in TypeScript and Fresh/Preact. In there I have to explicitly declare individual hooks ...
5
votes
1
answer
269
views
Flutter Cubit: 2 Screens and Listview
I try to program a small app to track my cost spendings. As state management I use Cubit. As I am a flutter beginner, I wanted to verify if I implemented it correctly.
The UI consists of 2 screens: 1 ...
-2
votes
2
answers
150
views
Is this a good way to advance one-by-one in an array of objects? [closed]
Using plain JavaScript, I want to load an array of objects, display the first one in a Bootstrap Card, and then click a button to advance to the next one. Focusing only on the point of getting the ...
2
votes
1
answer
96
views
Factory for state classes with varying numbers of reference data members
Consider the following code:
...
1
vote
1
answer
114
views
first React project - Lights Out game
I am working my way through a React tutorial on Scrimba (I am not finished yet). I got to a certain part that inspired me to try a project on my own. I made a game of Lights Out. If you've never heard ...
3
votes
1
answer
419
views
Unit test for a React click-counting component
Take this basic component using state:
...
0
votes
1
answer
136
views
Doubling of state to speed up UI performance in React with Redux
I have a settings section to my UI which keeps track of a myriad of user settings. The settings are requested from an API when the app loads, and then used in the section to populate what the user's ...
1
vote
1
answer
328
views
Another Vending Machine implementing State Pattern
I previously asked for a review for a Vending Machine implementing State Pattern in this linked post.
And received an answer from @radarbob. The code below is my revised attempt based on some of @...
5
votes
1
answer
621
views
Vending Machine implementing State Pattern
I was asked to implement a Vending Machine in a recent interview coding challenge. My attempt at a solution is based on the state pattern.
I would like to get some code reviews on this bearing in mind ...
6
votes
1
answer
2k
views
Date range generator
An app has a feature that's much like any calendar application (like the Outlook calendar for example).
Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...