Remove getOrDefault from ExtendedObservableMap (#2836)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-05-25 09:20:26 -04:00
1 parent 353a166b1e
commit 45d74b8c3a
2 files changed
+5 -27

No files matched your search

+2 -24
View File
@@ -19,7 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { action, IEnhancer, IObservableMapInitialValues, ObservableMap } from "mobx";
import { action, ObservableMap } from "mobx";
export class ExtendedMap<K, V> extends Map<K, V> {
static new<K, V>(entries?: readonly (readonly [K, V])[] | null): ExtendedMap<K, V> {
@@ -67,34 +67,12 @@ export class ExtendedMap<K, V> extends Map<K, V> {
}
export class ExtendedObservableMap<K, V> extends ObservableMap<K, V> {
constructor(protected getDefault: () => V, initialData?: IObservableMapInitialValues<K, V>, enhancer?: IEnhancer<V>, name?: string) {
super(initialData, enhancer, name);
}
@action
getOrInsert(key: K, val: V): V {
if (this.has(key)) {
return this.get(key);
}
return this.set(key, val).get(key);
}
@action
getOrInsertWith(key: K, getVal: () => V): V {
getOrInsert(key: K, getVal: () => V): V {
if (this.has(key)) {
return this.get(key);
}
return this.set(key, getVal()).get(key);
}
@action
getOrDefault(key: K): V {
if (this.has(key)) {
return this.get(key);
}
return this.set(key, this.getDefault()).get(key);
}
}