-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved data merging with component template (#14)
* Added processing of ValueReference in widgets at the stage of creating component descriptions * Fixed types, impl id replacement method * Upd package
- Loading branch information
Showing
8 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,78 @@ | ||
import 'package:duit_kernel/duit_kernel.dart'; | ||
|
||
/// Description of the component for registering it | ||
/// in the [DuitRegistry] under the key corresponding to the [tag] property | ||
final class DuitComponentDescription { | ||
final String tag; | ||
final Map<String, dynamic> data; | ||
final Set<RefWithTarget> refs; | ||
|
||
DuitComponentDescription({ | ||
required this.tag, | ||
required this.data, | ||
required this.refs, | ||
}); | ||
|
||
static void _replaceId(Map<String, dynamic> map) { | ||
final type = map["type"]; | ||
final timestamp = DateTime.now().microsecondsSinceEpoch; | ||
final id = "${type}_$timestamp"; | ||
map["id"] = id; | ||
} | ||
|
||
static void _prepareRefs( | ||
Map<String, dynamic> obj, | ||
Set<RefWithTarget> container, | ||
) { | ||
if (obj['controlled'] == true) { | ||
_replaceId(obj); | ||
} | ||
|
||
final attributes = obj['attributes'] as Map<String, dynamic>; | ||
final refs = attributes['refs']; | ||
|
||
if (refs != null) { | ||
final list = List.from( | ||
refs, | ||
growable: false, | ||
); | ||
|
||
for (final ref in list) { | ||
final rT = RefWithTarget( | ||
target: attributes, | ||
ref: ValueReference.fromJson(ref), | ||
); | ||
container.add(rT); | ||
} | ||
} | ||
|
||
if (obj['children'] != null) { | ||
final children = List.from( | ||
obj['children'], | ||
growable: false, | ||
); | ||
for (final child in children) { | ||
_prepareRefs(child, container); | ||
} | ||
} | ||
|
||
if (obj['child'] != null) { | ||
_prepareRefs(obj['child'], container); | ||
} | ||
} | ||
|
||
factory DuitComponentDescription.fromJson(Map<String, dynamic> json) { | ||
assert( | ||
json['tag'] != null, "Tag must be provided in component description"); | ||
assert(json['layoutRoot'] != null, | ||
"Layout must be provided in component description"); | ||
final root = json['layoutRoot']; | ||
final rf = <RefWithTarget>{}; | ||
_prepareRefs(root, rf); | ||
return DuitComponentDescription( | ||
tag: json['tag'], | ||
data: root, | ||
refs: rf, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import '../index.dart'; | ||
import 'package:duit_kernel/duit_kernel.dart'; | ||
|
||
/// The [FactoryRecord] is a [Record] of factory functions that can be used to build custom components | ||
typedef FactoryRecord = ({ | ||
AttributesFactory attributesFactory, | ||
ModelFactory modelFactory, | ||
BuildFactory buildFactory, | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:duit_kernel/duit_kernel.dart'; | ||
|
||
final class RefWithTarget { | ||
final Map<String, dynamic> target; | ||
final ValueReference ref; | ||
|
||
RefWithTarget({ | ||
required this.target, | ||
required this.ref, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters