-
Awesome package @rodydavis, I wanted to ask if you have explored ways to just use Maybe using extension methods as shown in this code: void main() {
final todos = signal([]);
print(todos.isEmpty);
final messages = signal({});
print(messages.keys);
}
Signal<T> signal<T>(T value) => Signal(value);
class Signal<T> {
const Signal(this.value);
final T value;
}
extension ListSignalExtension<E> on Signal<List<E>> {
bool get isEmpty => value.isEmpty;
}
extension MapSignalExtension<K, V> on Signal<Map<K, V>> {
Iterable<K> get keys => value.keys;
} |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
The first of implementation I started on this path because extensions are awesome and it was a pretty straightforward way to add getters. Ultimately, I needed to extend with value signal on these core types because of the mutations on some of the setters. I wanted to keep one object in memory, and allow for easy mutation. This might be no longer relevant with .forceUpdate on value signal. But Signal does not have that method for API concerns. Maybe I am being overly cautious and should move forceUpdate to the signal class. |
Beta Was this translation helpful? Give feedback.
-
Plus extensions cannot overload operators yet, but I believe there is a proposal for it. |
Beta Was this translation helpful? Give feedback.
-
Replicating class members is also not fun, because Dart unlike Swift does not support inheritance for Extensions. |
Beta Was this translation helpful? Give feedback.
-
Should I leave the issue open for exploration? |
Beta Was this translation helpful? Give feedback.
-
Another advantage of |
Beta Was this translation helpful? Give feedback.
-
Going to move this to a discussion! |
Beta Was this translation helpful? Give feedback.
The first of implementation I started on this path because extensions are awesome and it was a pretty straightforward way to add getters.
Ultimately, I needed to extend with value signal on these core types because of the mutations on some of the setters. I wanted to keep one object in memory, and allow for easy mutation.
This might be no longer relevant with .forceUpdate on value signal.
But Signal does not have that method for API concerns.
Maybe I am being overly cautious and should move forceUpdate to the signal class.