Parkour-Labs / dust

State management all-in-one: reactivity, persistence and synchronisation.
Apache License 2.0
2 stars 0 forks source link

Handle backlinks in constructor elements #14

Open wxxedu opened 4 months ago

wxxedu commented 4 months ago

Currently, if we specify backlinks in the constructor, their values would be ignored. For example, if we have a schema as follows:

@Model()
abstract class Folder with _$Folder {
  Folder._();

  factory Folder({
    required String name,
    @Ln() Folder? parent,
    @Ln(backTo: parent) List<Folder> children,
  }) = _Folder;
}

Then, if we do as following:

final child = Folder(name: 'child1');
final folder = Folder(name: 'parent', children: [child]);

Then an assertion error would be thrown. This is because currently there lacks a non-trivial way for me to add the child sensibly back to the parent, as we don't have an insert method to backlinks.

wxxedu commented 4 months ago

This is currently left here as is, because it would not hurt the user by much if

child.parent$.set(folder);