-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
## 1.4.3 | ||
|
||
- fix: memory leak caused by unused `@Setup` decorator | ||
## 1.4.2 | ||
|
||
- fix: Type failure | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
class SetupReference { | ||
private _count = 0; | ||
public map = new Map<object, number>(); | ||
public count() { | ||
this._count++; | ||
} | ||
public add(target: object) { | ||
this.map.set(target, this._count); | ||
this._count = 0; | ||
|
||
let count = 0; | ||
let isOpen = false; | ||
|
||
export function add () { | ||
if (isOpen) { | ||
count = 1; | ||
} else { | ||
isOpen = true; | ||
count++; | ||
} | ||
public reduce(target: object) { | ||
const { map } = this; | ||
let count = map.get(target)!; | ||
} | ||
|
||
const weakMap = new WeakMap<object, number>(); | ||
|
||
export function popTarget(target: object): boolean { | ||
let count = weakMap.get(target); | ||
if (typeof count === 'number') { | ||
count--; | ||
if (count) { | ||
map.set(target, count); | ||
weakMap.set(target, count) | ||
return false; | ||
} else { | ||
weakMap.delete(target); | ||
isOpen = false | ||
return true; | ||
} | ||
map.delete(target); | ||
return true; | ||
} | ||
return false | ||
} | ||
|
||
export const setupReference = new SetupReference(); | ||
export function bindTarget(target: object) { | ||
if (count > 0) { | ||
weakMap.set(target, count); | ||
count = 0; | ||
} else { | ||
console.warn(`The instance did not use the '@Setup' decorator`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters