From 3143f2a791e5ebbe785785436a1eaf8b9413653e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 7 May 2021 13:06:20 +0200 Subject: [PATCH] also make an observable version of a retained value --- src/observable/ObservableValue.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/observable/ObservableValue.js b/src/observable/ObservableValue.js index 3fbfe463..8a433444 100644 --- a/src/observable/ObservableValue.js +++ b/src/observable/ObservableValue.js @@ -94,6 +94,18 @@ export class ObservableValue extends BaseObservableValue { } } +export class RetainedObservableValue extends ObservableValue { + constructor(initialValue, freeCallback) { + super(initialValue); + this._freeCallback = freeCallback; + } + + onUnsubscribeLast() { + super.onUnsubscribeLast(); + this._freeCallback(); + } +} + export function tests() { return { "set emits an update": assert => {