Convert RetainedValue.js to ts

This commit is contained in:
RMidhunSuresh 2021-11-16 15:41:50 +05:30
parent 88ec1b575d
commit ea0adb4407
2 changed files with 7 additions and 5 deletions

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import {ObservableMap} from "../../../observable/map/ObservableMap.js";
import {RetainedValue} from "../../../utils/RetainedValue.js";
import {RetainedValue} from "../../../utils/RetainedValue";
export class MemberList extends RetainedValue {
constructor({members, closeCallback}) {

View file

@ -15,16 +15,18 @@ limitations under the License.
*/
export class RetainedValue {
constructor(freeCallback) {
private readonly _freeCallback: () => void;
private _retentionCount: number = 1;
constructor(freeCallback: () => void) {
this._freeCallback = freeCallback;
this._retentionCount = 1;
}
retain() {
retain(): void {
this._retentionCount += 1;
}
release() {
release(): void {
this._retentionCount -= 1;
if (this._retentionCount === 0) {
this._freeCallback();