Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/mix/lib/src/core/prop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ class Prop<V> {
throw FlutterError('Prop<$V> has no sources');
}

if (sources.length == 1) {
final source = sources.first;
if (source is ValueSource<V> && source.value is! Mix<V>) {
return PropOps.applyDirectives(source.value, $directives);
}
}

// Resolve all sources to values
final values = [];
for (final source in sources) {
Expand Down
23 changes: 23 additions & 0 deletions packages/mix/test/src/core/prop_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ void main() {
expect(resolved, equals(42));
});

test('applies directives after resolving a single direct source', () {
final prop = Prop.value(
21,
).directives([MockDirective<int>('double', (value) => value * 2)]);

expect(prop.resolveProp(MockBuildContext()), 42);
});

test('resolves a Mix stored as a single direct source', () {
final mix = MockMix<Object>(42);
final prop = Prop.value<Object>(mix);

expect(prop.resolveProp(MockBuildContext()), 42);
});

test('resolves a Mix returned by a single token source', () {
final token = TestToken<Object>('mixed');
final prop = Prop.token(token);
final context = MockBuildContext(tokens: {token: MockMix<Object>(42)});

expect(prop.resolveProp(context), 42);
});

test('merges value and token sources (universal accumulation)', () {
final token = TestToken<int>('n');
final p1 = Prop.value(1);
Expand Down
Loading