findIn method

T findIn(
  1. LevitScope scope, {
  2. String? tag,
})

Finds or creates the store instance within scope.

Uses optional tag to isolate independent instances of the same store definition.

Throws if builder throws while creating the store value.

Implementation

T findIn(LevitScope scope, {String? tag}) {
  final instanceKey =
      tag != null ? 'ls_store_${_getStoreTag(this, tag)}' : _defaultKey;

  var instance = scope.findOrNull<_LevitStoreInstance<T>>(tag: instanceKey);

  if (instance == null) {
    scope.put(() => _LevitStoreInstance<T>(this), tag: instanceKey);
    instance = scope.find<_LevitStoreInstance<T>>(tag: instanceKey);
  }

  return instance.value;
}