still call constructor...
parent
13c0ef1173
commit
f9cace7815
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "frigid",
|
||||
"version": "1.1.2",
|
||||
"version": "1.2.0",
|
||||
"main": "out/index.js",
|
||||
"types": "out/index.d.ts",
|
||||
"license": "MIT",
|
||||
|
|
|
|||
|
|
@ -7,18 +7,22 @@ export const RESTORE = Symbol('RESTORE');
|
|||
export default class Frigid extends Serializable {
|
||||
static create(filename: string, ...args: any[]) {
|
||||
if(existsSync(filename)) {
|
||||
const instance = this.deserialize(readFileSync(filename));
|
||||
const instance = new this(...args);
|
||||
const instanceStuff = this.deserialize(readFileSync(filename));
|
||||
for(const key of Object.keys(instanceStuff)) {
|
||||
instance[key] = instanceStuff[key]
|
||||
}
|
||||
// TS is plain and simply wrong... symbols can be used to index object...
|
||||
// @ts-ignore
|
||||
instance[PERSIST_LOCATION] = filename;
|
||||
instance[RESTORE]();
|
||||
instance[RESTORE]?.();
|
||||
return instance;
|
||||
} else {
|
||||
const instance = new this(...args);
|
||||
// again... TS is wrong...
|
||||
// @ts-ignore
|
||||
instance[PERSIST_LOCATION] = filename;
|
||||
instance[RESTORE]();
|
||||
instance[RESTORE]?.();
|
||||
instance.sync();
|
||||
return instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ expect(trackingData.restoreCalls).to.equal(1);
|
|||
|
||||
const retest = Test.create(filepath);
|
||||
|
||||
expect(trackingData.constructorCalls).to.equal(1);
|
||||
expect(trackingData.constructorCalls).to.equal(2);
|
||||
expect(trackingData.restoreCalls).to.equal(2);
|
||||
|
||||
unlinkSync(filepath)
|
||||
Reference in New Issue