From 942fd7c0437a0be43bf4b9370f1e45e1aebd79de Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Mon, 13 Jul 2026 04:25:22 -0400 Subject: [PATCH] refactor(mix): optimize single-value prop resolution --- packages/mix/lib/src/core/prop.dart | 7 +++++++ packages/mix/test/src/core/prop_test.dart | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/mix/lib/src/core/prop.dart b/packages/mix/lib/src/core/prop.dart index 9c98e8e57..eeabd106e 100644 --- a/packages/mix/lib/src/core/prop.dart +++ b/packages/mix/lib/src/core/prop.dart @@ -214,6 +214,13 @@ class Prop { throw FlutterError('Prop<$V> has no sources'); } + if (sources.length == 1) { + final source = sources.first; + if (source is ValueSource && source.value is! Mix) { + return PropOps.applyDirectives(source.value, $directives); + } + } + // Resolve all sources to values final values = []; for (final source in sources) { diff --git a/packages/mix/test/src/core/prop_test.dart b/packages/mix/test/src/core/prop_test.dart index ec2a008a8..f67a99053 100644 --- a/packages/mix/test/src/core/prop_test.dart +++ b/packages/mix/test/src/core/prop_test.dart @@ -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('double', (value) => value * 2)]); + + expect(prop.resolveProp(MockBuildContext()), 42); + }); + + test('resolves a Mix stored as a single direct source', () { + final mix = MockMix(42); + final prop = Prop.value(mix); + + expect(prop.resolveProp(MockBuildContext()), 42); + }); + + test('resolves a Mix returned by a single token source', () { + final token = TestToken('mixed'); + final prop = Prop.token(token); + final context = MockBuildContext(tokens: {token: MockMix(42)}); + + expect(prop.resolveProp(context), 42); + }); + test('merges value and token sources (universal accumulation)', () { final token = TestToken('n'); final p1 = Prop.value(1);