New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an empty unmodifiable map implementation #172
Conversation
UnmodifiableMapMixin was missing a handful of methods that change a Map. The mixin was synced to _UnmodifiableMapMixin from dart:collection. Removed the first and last setter since they don't correspond to Map methods.
@kevmoo @natebosch I think this would help simplify some of the class Context extends UnmodifiableMapView<String, Object> {
factory Context(Map<String, Object> from) {
if (from is Context) return from;
if (from.isEmpty) return Context.empty();
return Context._(from);
}
const factory Context.empty() = _EmptyContext;
Context._(Map<String, Object> from) : super(from);
}
class _EmptyContext extends EmptyUnmodifiableMap<String, Object>
implements Context {
const _EmptyContext();
} |
Ooo! Tests? |
Sure! Wanted to make sure that the changes were acceptable before writing tests. Version would be 1.15.0-nullsafety.6? I'm assuming after null safety lands the package is being bumped to 2.0 right? |
Let @natebosch chime in before you do any more... |
Could we skip the extra class and use class Context extends UnmodifiableMapView<String, Object> {
factory Context(Map<String, Object> from) {
if (from is Context) return from;
if (from.isEmpty) return empty;
return Context._(from);
}
static final empty = Context._(const {});
Context._(Map<String, Object> from) : super(from);
} Or, if we make the class _EmptyContext extends UnmodifiableMapView<String, Object>
implements Context {
const _EmptyContext(): super(const {});
} or without the empty class, but keeping the class Context extends UnmodifiableMapView<String, Object> {
factory Context(Map<String, Object> from) {
if (from is Context) return from;
if (from.isEmpty) return Context.empty();
return Context._(from);
}
const Context.empty() : this._(const {});
const Context._(Map<String, Object> from) : super(from);
}
I don't think I see a reason we'd need this class in this library. I'd be happy to explore whether we can make the existing constructor |
No, this and a few other very core packages are migrating to null safety without a major version bump because an early choice by the Flutter framework makes it infeasible to do breaking releases. |
Closing as assumed stale |
Adds an
EmptyUnmodifiableMap
implementation which provides aconst
constructor.The
Mixin
classes withinunmodifiable_wrappers.dart
were changed fromabstract class
tomixin
to modernize the code. This allowed theEmptyUnmodifiableMap
to have aconst
constructor without also defining aconst
constructor inUnmodifiableMapMixin
.