phosphorjs / phosphor

The PhosphorJS Library
BSD 3-Clause "New" or "Revised" License
1.04k stars 169 forks source link

Update datastore helpers #440

Closed ian-r-rose closed 4 years ago

ian-r-rose commented 4 years ago

Follow up to #418. This keeps the reference to the datastore separate from the reference to tables, records, and fields.

So instead of the previous data locations specified like

loc1 = {
  datastore: Datastore;
  schema: S;
  record: string;
};
loc2 = {
  datastore: Datastore;
  schema: S;
  record: string;
  field: string;
};

we have something like

{
  datastore: Datastore;
  loc1: {
    schema: S;
    record: string;
  };
  loc2: {
    schema: S;
    record: string;
    field: string;
  };
}

I have found that this works a bit better for more complex compound data models which might need to contain references to multiple locations in a datastore. For instance, a cell model will need to know the location of its text field, as well as a location to a table of cell outputs. This enforces via the type system that the datastores for those two locations are the same, and provides a more natural data structure for describing all the data that a particular widget needs to render itself.