restructure
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
Some checks failed
CI - Multi-Platform Native / Build iOS (RSSuper) (push) Has been cancelled
CI - Multi-Platform Native / Build macOS (push) Has been cancelled
CI - Multi-Platform Native / Build Android (push) Has been cancelled
CI - Multi-Platform Native / Build Linux (push) Has been cancelled
CI - Multi-Platform Native / Build Summary (push) Has been cancelled
This commit is contained in:
34
linux/src/state/ErrorType.vala
Normal file
34
linux/src/state/ErrorType.vala
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ErrorType.vala
|
||||
*
|
||||
* Error types for state management
|
||||
*/
|
||||
|
||||
namespace RSSuper {
|
||||
|
||||
/**
|
||||
* ErrorType - Category of errors
|
||||
*/
|
||||
public enum ErrorType {
|
||||
NETWORK,
|
||||
DATABASE,
|
||||
PARSING,
|
||||
AUTH,
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
/**
|
||||
* ErrorDetails - Detailed error information
|
||||
*/
|
||||
public class ErrorDetails : Object {
|
||||
public ErrorType type { get; set; }
|
||||
public string message { get; set; }
|
||||
public bool retryable { get; set; }
|
||||
|
||||
public ErrorDetails(ErrorType type, string message, bool retryable = false) {
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
this.retryable = retryable;
|
||||
}
|
||||
}
|
||||
}
|
||||
110
linux/src/state/State.vala
Normal file
110
linux/src/state/State.vala
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* State.vala
|
||||
*
|
||||
* Reactive state management using GObject signals
|
||||
*/
|
||||
|
||||
namespace RSSuper {
|
||||
|
||||
/**
|
||||
* State - Enumerated state for reactive state management
|
||||
*/
|
||||
public enum State {
|
||||
IDLE,
|
||||
LOADING,
|
||||
SUCCESS,
|
||||
ERROR
|
||||
}
|
||||
|
||||
/**
|
||||
* State<T> - Generic state container with signals
|
||||
*/
|
||||
public class State<T> : Object {
|
||||
private State _state;
|
||||
private T? _data;
|
||||
private string? _message;
|
||||
private Error? _error;
|
||||
|
||||
public State() {
|
||||
_state = State.IDLE;
|
||||
}
|
||||
|
||||
public State.idle() {
|
||||
_state = State.IDLE;
|
||||
}
|
||||
|
||||
public State.loading() {
|
||||
_state = State.LOADING;
|
||||
}
|
||||
|
||||
public State.success(T data) {
|
||||
_state = State.SUCCESS;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public State.error(string message, Error? error = null) {
|
||||
_state = State.ERROR;
|
||||
_message = message;
|
||||
_error = error;
|
||||
}
|
||||
|
||||
public State get_state() {
|
||||
return _state;
|
||||
}
|
||||
|
||||
public T? get_data() {
|
||||
return _data;
|
||||
}
|
||||
|
||||
public string? get_message() {
|
||||
return _message;
|
||||
}
|
||||
|
||||
public Error? get_error() {
|
||||
return _error;
|
||||
}
|
||||
|
||||
public bool is_idle() {
|
||||
return _state == State.IDLE;
|
||||
}
|
||||
|
||||
public bool is_loading() {
|
||||
return _state == State.LOADING;
|
||||
}
|
||||
|
||||
public bool is_success() {
|
||||
return _state == State.SUCCESS;
|
||||
}
|
||||
|
||||
public bool is_error() {
|
||||
return _state == State.ERROR;
|
||||
}
|
||||
|
||||
public void set_idle() {
|
||||
_state = State.IDLE;
|
||||
_data = null;
|
||||
_message = null;
|
||||
_error = null;
|
||||
}
|
||||
|
||||
public void set_loading() {
|
||||
_state = State.LOADING;
|
||||
_data = null;
|
||||
_message = null;
|
||||
_error = null;
|
||||
}
|
||||
|
||||
public void set_success(T data) {
|
||||
_state = State.SUCCESS;
|
||||
_data = data;
|
||||
_message = null;
|
||||
_error = null;
|
||||
}
|
||||
|
||||
public void set_error(string message, Error? error = null) {
|
||||
_state = State.ERROR;
|
||||
_message = message;
|
||||
_error = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user