Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Fixing validation, highlighting and authoring state #181

Merged
merged 6 commits into from
Dec 18, 2018

Conversation

yuricus
Copy link
Member

@yuricus yuricus commented Dec 14, 2018

No description provided.

@yuricus
Copy link
Member Author

yuricus commented Dec 14, 2018

LGTM

if (!isNew) { return true; }

const linkModel = (event as LinkChange).after;
const isConnectedToTheElements = elementIris.find(elementIri => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use Set<ElementIri> instead of an array, you'll be able to perform this test in two calls:

elementIris.has(linkModel.link.sourceId) || elementIris.has(link.targetId);

): AuthoringState {
const events = state.events.filter(event => {
const isNew = event.type === AuthoringKind.ChangeLink && !event.before;
if (!isNew) { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend testing this directly (without isNew variable):

if (!(event.type === AuthoringKind.ChangeLink && !event.before)) { return true; }

This way you won't need a cast later: (event as LinkChange)

for (const item of items) {
if (item instanceof Element) {
if (AuthoringState.isNewElement(state, item.iri)) {
if (AuthoringState.isNewElement(this.authoringState, item.iri)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be easier to replace this whole if-statement with something like this:

this.discardChange(event);
this.model.removeElement(item.id);

This way you don't even need to have deleteNewLinksReleatedToElements() method at all.

// delete newly created entity
for (const element of elements) {
this.model.removeElement(element.id);
const isOriginalEntity = !event || event.type === AuthoringKind.ChangeElement && event.before;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block could be simplified by reusing discardChange() logic a little bit more:

// remove new connected links
const linksToRemove = new Set<string>();
for (const element of elements) {
    for (const link of element.links) {
        if (link.data && AuthoringState.isNewLink(state, link.data)) {
            linksToRemove.add(link.id);
        }
    }
}
// delete separately to prevent modification while iterating
linksToRemove.forEach(linkId => this.model.removeLink(linkId));

if (event) {
    this.discardChange(event);
}

const batch = this.model.history.startBatch();
const dangerousIris: ElementIri[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's so dangerous about these?

@AlexeyMz AlexeyMz merged commit cda1297 into master Dec 18, 2018
@AlexeyMz AlexeyMz deleted the fix-authoring-state-backport branch March 28, 2019 14:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants