Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Sync observable collections in Twins #36

Open
andreyvit opened this Issue · 1 comment

1 participant

@andreyvit
Owner

Right now, Twins library does not handle entity collections in any way, and the goal of this ticket is to add first-class support for collections.

Current state

Twins can only:

  • perform assignments of simple atomic values (like strings) to entity properties,
  • navigate to existing named subentities (#mainwnd #addProjectButton).

It cannot:

  • create new entities
  • delete entities
  • sync lists of entities (i.e. create / delete / update)

While some supported controls (TreeView) can accept a collection of items, the collection is basically treated like an atomic value, and each item does not become an entity.

This has been an acceptable workaround for single-level trees, but won't work when syncing view models, where each item is an entity of its own, and has to participate in further subentity syncing.

Goal

We want an update like this:

{
    "#mainwnd": {
        "#actionGroups": [
            {
                "id": "stylesheets",
                "title": "stylesheets",
                "#actions": [
                    {
                        "id": "compile.sass",
                        "name": "compile sass",
                        "#rules": [
                            {
                                "id": "R12345",
                                "sourceMask": "*.sass",
                                "destinationMask": "*.css",
                                "#files": [
                                    {
                                        "id": "F1234",
                                        "enabled": true,
                                        "sourcePath": "foo.sass",
                                        "destinationPath": "foo.css"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

to sync the list of ActionGroups, Actions, Rules and RuleFiles inside the view model.

Implementation

Entity syncing should be performed when we reach a property of ObservableCollection type. This property will always be treated as read-only, and the returned collection will be manipulated instead of being overwritten.

We want to create an EntityCollection class to track the list of subentities inside the entity.

It's safe to assume that every model class that we want to sync this way has to provide a string Id property, and we probably want to define a C# interface for that.

We'll need to know which C# class to create when new entities are added; for that, we can probably provide some reasonable default logic (based on the generic type of the ObservableCollection), overridable using an optional interface implemented by the parent entity.

@andreyvit andreyvit closed this in 6fd2783
@andreyvit
Owner

Actually, still need to actually sync the children (right now they are simply overwritten), so reopening.

@andreyvit andreyvit reopened this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.