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.

Filter by
Sorted by
Tagged with
6
votes
0answers
40 views

React state management design pattern new approach thoughts

Hey people on the internet! I do not know where to share my new npm package so I am asking you do you know of a good place to share my package? Also I would really appreciate if you take a look on it ...
2
votes
0answers
29 views

Storing localStorage data as part of rxjs reducer?

I use ngrx in my Angular app to state management. At a certain time I was asked to save some variable to local storage and retrieve it with first load. That made ...
2
votes
0answers
35 views

Switching article states using state pattern

The Article model supports a bunch of transitions. Only two are shown below: star()/unstar()....
1
vote
0answers
14 views

Custom Global Store using React.js context and hooks

I wanted to use an external global state to a React.js application with a redux-like sort of pattern (with reducers, actions, etc). However, I don't want to use redux itself, as it's just a small ...
3
votes
2answers
55 views

Scalable design of a system with multiple state machines, where valid state transitions depend on the state of other machines

This is a pretty huge question, however, I would appreciate it if you could just review the design and not my implementations of it. The Implementation and test sections could be ignored, they are ...
6
votes
4answers
570 views

Section 2: Classes - Design a StackOverflow Post

Design a class called Post. This class models a StackOverflow post. It should have properties for title, description and the date/time it was created. We should be able to up-vote or down-vote a ...
3
votes
1answer
86 views

Haskell - Caching third party API token across requests

The following code is designed to cache a (UTCTime, Text) value that keeps the Text token around until it expires, preventing ...
3
votes
2answers
121 views

Persisting Variables Over A State Loss

In an application that I built recently, I needed to persist several variables, without loosing their state, for duration that the application was in use. After some research, I found this post on ...
2
votes
1answer
90 views

Simpler state manament alternative to Redux, MobX, Context API, etc

I got frustrated with the jargon and created an alternative state management solution. Its up at https://github.com/smakazmi/react-soliit. It goes something like this ...
1
vote
1answer
77 views

Toggle between two options in an object?

I have just written this code for toggling between two possible states of an object. ...
2
votes
2answers
62 views

N rotations of an array, either left or right, and then printing the result

Disclaimer, I'm new to OOP, but have experience in haskell and javascript. Essentially, the challenge was to create a program which would shift an array a given amount of times to the left and then ...
3
votes
3answers
113 views

Cooking steak with State Pattern and without IFs

I've been playing around a bit with a case of State Pattern but including as well ranges in order to get into a specific state. So the definition is as simple as this: There is a Steak that has a ...
1
vote
1answer
35 views

View for logging telephone calls

As part of a web-based claims system I have created, there is a view for logging telephone calls. If a call is incoming, the claims handler asks the caller a series of data protection questions to ...
2
votes
1answer
47 views

Checking user verification status

The User story is as follows: Users are allowed to get "verified", so other users know they have passed a background check. After tapping "get verified" button, or the "verification badge" ...
2
votes
2answers
231 views

getDerivedStateFromProps [closed]

Starting from React 16.3 there are some new lifecycle methods introduced. One of them is the static getDerivedStateFromProps(props,state) method. This method ...
4
votes
4answers
740 views

State Pattern for traffic lights

I tried to implement a traffic light system using state pattern, please comment on the OOP/design pattern use. ...
13
votes
0answers
1k views

Realtime concurrent Haskell MIDI buffer

Problem Background MIDI is a serial representation of control signals to a sound generator. Typically, a noteOn message initiates the attack phase of a sound at a given pitch. The note will ...
1
vote
1answer
163 views

Currency exchange app

I'm making a currency exchange app, it works as follows: User types in on desired currency input and the rest of the input fields change with state based on the currency value from the input used, I'...
6
votes
1answer
459 views

State Monad in TypeScript

Here's my implementation of State Monad in TypeScript, based on a canonical Haskell implementation. I would like it to get code reviewed. ...
1
vote
1answer
48 views

Using an alternative for a switch/state-based custom parser

I'm currently developing a small tool that applies a number of regex-based match/replacement-pairs to the contents of a file (or, more generally speaking, a string). Note that regex-knowledge is not ...
0
votes
1answer
3k views

Toggle between two states in react

I have two fetch calls which updates the state. And I have two buttons. One makes a fetch call, another calls componentDidMount()...
1
vote
0answers
37 views

3 state switch for a table sort

I have a data table with 7 columns. The first column is the index that increases from 1 to N and is considered to be in ascending order by default. The remaining columns are unsorted. I need to be ...
7
votes
1answer
623 views

Elegant output separators

Today I found myself reinventing output separators for the zillionth time. I have converged on an approach like the following that seem pretty clean: Live On Coliru ...
28
votes
3answers
2k views

A Failable<T> that allows safe returning of exceptions

This was inspired by a conversation in chat, that started with the discussion of C#7.0 tuples and out parameter declarations, which led to the idea that there is no 'good1' way to return an error ...
5
votes
1answer
82 views

Logon state management

I'm in the process of writing a simple text based MUD. First up is making sure that it's possible to create new players / logon with existing players. Since everything is text based, there are ...
3
votes
1answer
96 views

ApplicationSettings Class for disabling/restoring Application State

This previous iteration of this question can be found here A utility class to handle the state of the Application object. Storing the application's initial state (...
-2
votes
1answer
46 views

Capture some state in Haskell

I want to capture some state in a Haskell function. For instance, I have many thread trying to print on the console and I want the to play nice with each other. So I want to have some XX to make the ...
7
votes
2answers
528 views

Evaluating Parser State

The "parser state" of a module in rubberduck can be one of several values: ...
1
vote
0answers
600 views

Managing the state of multiple, similar, selects in React Form

I have a really simple form with 3 select boxes for days, hours, and minutes (in the full code I have a submit button attached to an ajax request). And I've got each of those select boxes attached to ...
4
votes
1answer
1k views

(C++14) Handling state in C-style function pointer callbacks

I'm having some issues coming up with a sensible solution for using shared state in a C-style function pointer. I am using GLFW to handle my OpenGL context and have created a thin wrapper around all ...
5
votes
1answer
1k views

Model of an mp3 player with state and prototype design patterns

After reading about design patterns in general, I decided to try and incorporate them in an actual program. I chose a State machine for my first exercise, or, more concretely, an MP3 player. The ...
3
votes
1answer
237 views

Is my design still a state design pattern, or some abomination?

I was trying to review state design pattern, and tried to create flexible implementation of it so it could reuse it in future. So I came out with this: ...
8
votes
1answer
533 views

HangPerson in Haskell

I created a HangPerson game in Haskell and I must admit it feels very imperative. How can I make it more "functional?" Are there more elegant ways of breaking up the task? The ...
6
votes
2answers
13k views

Console application menu

Sometimes I need to write a simple Java console applications and menu look: ...
5
votes
1answer
252 views

Untouchable Numbers

I wrote this program in response to a CodeGolf challenge that required generating this sequence of "untouchable" numbers. This sequence can be found on OEIS as A005114. My initial implementation was ...
3
votes
1answer
499 views

Using C++11 move semantics to implement state pattern

I'm implementing a C++ layer on top of the sockets api of the OS (i.e. man 7 socket)1. Tcp sockets go through various states. Using the RAII principle leads to distinguishing the states: ...
1
vote
1answer
339 views

Managing state in Clojure

Where should you store state and how should it be managed in a ClojureScript application? Take the following code for example - it's a "game" where you travel either down or left. ...
4
votes
1answer
326 views

Huge terminal game (in development)

I'm developing a big (for me, as a beginner) terminal program "Brainfuck - The Game", in which you have to complete Brainfuck challenges. I would like your review on existing code (and project ...
2
votes
1answer
81 views

Polymorphic components for graphics and program state

I asked this question on StackOverflow, got some answers, most notably a link to this one, and basing on that I've implemented this: ...
2
votes
1answer
2k views

Reading and Writing object from files

I have a server which has a permanent state which has to be saved on stable storage. It is composed by three fields: List<LogEntry> log ...
3
votes
0answers
360 views

ThreeJS State Object

state object - a state or scene from the game. When the start function is called, the state starts rendering, shutting down any other state using the renderer, and calling the specified functions (...
4
votes
1answer
176 views

Encapsulated state in clojure

While going through SICP and trying to implement the code in clojure, I've found that while I can get the code in chapter 3 to work, it seems to go against Clojure idioms, but I can't quite imagine ...
4
votes
1answer
146 views

Simple attribute parser for HTML

I am studying Java and trying to write an HTML parser, which should parse tag names and attributes. I wrote a class (code below) using the State pattern. This is necessary for my training project, ...
2
votes
0answers
45 views

Expressing computations on values as State

I was writing an application with a few Monads in a transformer stack. The top level application state resides in a TVar, and various components of the application ...
8
votes
3answers
454 views

Handling shared state among a lot of elements in Angular

I am working on a project in Angular where I have a number of similar data objects. When you click on anyone of them it's state and amount of data shown will change. All of the objects start in the ...
7
votes
4answers
338 views

Memory usage in Reversi board state

I'm coding a Reversi game, with an artificial intelligence using the MinMax as the search algorithm. My concern is that (most) search algorithms needs to store a lot of instances of "states", in my ...
3
votes
1answer
1k views

Simple Javascript state management class

So I needed very basic state management and notification for a small game-like thing I'm building. I decided to implement something like a finite state machine (but not quite, it doesn't transition ...
5
votes
2answers
87 views

Static variable representing program state accessed with multiple functions

I have this method that performs certain functions based on the state that the algorithm is currently at: ...
2
votes
2answers
444 views

Counting occurrences of Char8s in a file

To learn some Data.Map and Control.Monad.State, I have written the following code, which should count the occurrences of ...
3
votes
0answers
295 views

jQuery Plugin - HTML5 History State

I've built this small jQuery plugin to work with HTML5 History State functions. It's my first jQuery plugin, so I'm not sure if it's up to the best practices, or what could be done better. Keeping it ...