getOrPut<T extends Object> method

T getOrPut<T extends Object>({
  1. Object? key,
  2. required T ifAbsent(
    1. Lifecycle lifecycle
    ),
  3. LifecycleExtDataOnDestroy<T>? onDestroy,
})

根据Type + key获取,如果不存在则创建信息

Implementation

T getOrPut<T extends Object>({Object? key,
  required T Function(Lifecycle lifecycle) ifAbsent,
  LifecycleExtDataOnDestroy<T>? onDestroy}) {
  final lifecycle = _lifecycle?.target;
  if (_isDestroyed || lifecycle == null) {
    throw Exception('extData has been destroyed.');
  }
  return _data
      .putIfAbsent(_genKey<T>(key: key),
          () => _ExtDataEntry<T>(ifAbsent(lifecycle), onDestroy))
      .data;
}