Table of Contents

Data sharing

What is data sharing ?

Data sharing is a mechanism that allows you to share a data source between multiple UI views.
This offers several advantages :

  • changes made to the data by one UI view is automatically propagated to all the UI views it shares its data with
  • only one request to fetch data is made by the main UI view instead of one request by UI view

Using data sharing

In a UI template

The <ui-view> component provides argument data-shared-with for sharing data.

See more information.

When navigating

When navigating by code, the NavigationOptions provides the WithDataSharing method for sharing data.

See more information.

When to use data sharing ?

When dealing with a complex UI view, it can be useful to cut it in several parts to be able partition it by theme and be able to reuse the smaller UI views in other parts of the application.
For example, if we have a party edit UI view that contains a big template, we might want to isolate the customer account information in a separate UI view and reuse it in a invoice UI.

<ui-view name="CustomerAccountUI" data-shared-with="#Main" />

You can also use data sharing when opening a new screen / modal popup by navigating. Doing so, the opened UI view will not load its data and use the shared data as its data source.
This can be useful to isolate the content of a modal popup.

NavigationOptions options = new NavigationOptions(UIViews.NewCustomerAccountUI)
    .OnTarget(NavigationTarget.Popup)
    .WithDataSharing(Datasource, Position);
await NavigateAsync(options);

Constraints

Because a UI view opened with data sharing gets its data from a parent UI view, they both must use a compatible structure.

Consider a UI view A that shares its data with a UI view B :

  • UI view A must be based on an entity view similar to the entity view UI view B is based.
    This means that while entity view A and entity view B can be different, all the bound properties of entity view B must exist on entity view A.
  • UI view A must contain subviews that are similar to the ones existing on UI view B.
    Consider a subview name SV existing on UI view B.
    This means that :
    • a subview with the same name must exist on UI view A
    • the subview on UI view A can use a different UI view than the one on UI view B
    • the subview on UI view A must use a UI view based on the same entity view as the one on UI view B

Identifying data sharing with incoherent UI views

Neos cannot detect when generating that the above constraints are not respected because data sharing can be used when navigating by code.
However you will be notified when opening a screen using an incoherent data sharing configuration :

  • in development, an error popup listing the problems is displayed and an error is logged in the browser console
  • in production, an error is logged in the browser console

In both cases, you will be able to see these errors in Application Insights if it is configured for the cluster.