Files
discord-decomp/lib/StateManager.tsx
T
2026-11-01 12:12:55 +02:00

64 lines
1.4 KiB
TypeScript

// Metro module 12732 (f12733).
import isUndefinedOrNull from "../_bundle/isUndefinedOrNull";
class StateManager {
constructor(alwaysUpdateState = true) {
const r5 = {
__proto__: new.target.prototype,
dirty: false
};
r5.state = r5.getInitialState();
r5.alwaysUpdateState = alwaysUpdateState;
return r5;
}
shouldCommit() {
return true;
}
setState(a0) {
this.state = {
...this.state,
...a0
};
}
getState() {
return this.state;
}
reset() {
this.dirty = false;
this.state = this.getInitialState();
}
update(r7 = {}, r2 = false) {
const nextState = this.getNextState({
...this.state,
...r7
});
if (r2) {
this.dirty = !isUndefinedOrNull(nextState, this.getInitialState());
} else {
for (const item of Object.keys(nextState)) {
let dirty = this.dirty;
if (!dirty) {
const state = this.state;
dirty = !isUndefinedOrNull(state[item], nextState[item]);
}
this.dirty = dirty;
}
}
const r55 = this.dirty && this.shouldCommit();
if (r55 || this.alwaysUpdateState) {
this.state = nextState;
}
let r59 = !!r55;
if (r59) {
this.dirty = false;
this.didCommit(this.state);
r59 = true;
}
return r59;
}
forceUpdate() {
this.dirty = false;
this.didCommit(this.state);
}
}
export default StateManager;