Skip to content

Update Edit API handles namespaced attributes poorly #132

@ca-d

Description

@ca-d

The Update event could use an update, since the current handling of namespaced attribute updates is both cumbersome and - in one edge case - insufficient.

Currently attributes are grouped by (unprefixed) name and attach an extra namespaceURI parameter to the value:

const update: Update = {
  element,
  attributes: { attrName: { namespaceURI: 'https://example.org/myNS', value: 'attrValue' } }
}

The cumbersome aspect is that namespaceURI is quite long to type.

The functionally insufficient aspect is that this disallows setting two different attributes from two different namespaces if they happen to be named the same, e.g. if I wanted to simultaneously set both the svg:x attribute and the sxy:x attribute from the SVG and IEC 61850-6 Annex C.1 namespaces, respectively.

I suggest changing this part of the API by separating namespaced from non-namespaced attributes in the update event like so:

const updateV2: UpdateV2 = {
  element,
  attributes: { attrName: 'attrValue' } // non-namespaced attrs only
  attributesNS: { 'https://example.org/myNS': { attrName: 'attrValue' } }
}

resulting in a new type

export type UpdateV2 = {
  element: Element;
  attributes: Partial<Record<string, string | null>>;
  attributesNS: Partial<Record<string, Partial<Record<string, string | null>>>>;
};

Since this project is still in alpha, I think the new type could actually replace the current Update type without too much trouble, which seems preferable to me. If this does not happen until the first stable version of open-scd-core is released, I would then tend more to adding a new UpdateV2 type in addition to the old one and consequently supporting the deprecated legacy API til kingdom come.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions