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ZEJZLDCGEIPXRCVNF6YBSQC
AAKN4XJLZ2GARZMUFYX3CJZKYHTRRZDYNTFRLMY7VPAY7K6W4N3QC
A75BWKGRLUDH3KF4M2HJYLNC6BSV5MAJFV2RJSF757F46HLRLCKQC
THNMNMVRZQVPZTEXHIK6WGYN3QDEFPKFOVOCB5HTWCYC5BOBYQ5AC
const [gameState, setGameState] = useState<GameState>(
new GameStateFactory({}).create()
);
// const x_initialGameState = useMemo(() => new GameStateFactory({}).create(), []);
// const [gameState, setGameState] = useState<GameState>(x_initialGameState);
const [gameState, setGameState] = useState<GameState>(initialGameState.get());
// const [gameState, setGameState] = useState<GameState>(() => new GameStateFactory({}).create());
// useEffect(() => {
// setGameState(new GameStateFactory({}).create());
// }, []);
// if (!gameState) {
// setGameState(new GameStateFactory({}).create());
// }
// if (gameState === undefined) {
// throw new Error();
// }
const [application, setApplication] = useState<Application>(
new Application({
originalWindowWidth: window.innerWidth,
originalWindowHeight: window.innerHeight,
})
);
const [application, setApplication] = useState<Application>(initialApplication.get());
}
const assertOnlyCalledOnceData: { [k: string]: string } = {};
export function assertOnlyCalledOnce(id: string | number) {
let k = id.toString();
if (assertOnlyCalledOnceData[k] !== undefined) {
throw new Error("Error, called twice with same id: " + k + " , callback the first time was : " + assertOnlyCalledOnceData[k]);
} else {
const stacktrace = new Error().stack!
assertOnlyCalledOnceData[k] = stacktrace;
}
}
export class Lazy<T> {
private _wasConstructed: boolean = false;
private _value: T | undefined = undefined;
private _factory: () => T
constructor(factory: () => T) {
this._factory = factory;
}
public get(): T {
// T might have undefined as a valid value
if (this._value !== undefined || this._wasConstructed === true) {
return this._value!;
} else {
this._value = this._factory();
this._wasConstructed = true;
return this._value;
}
}