Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow filtering mutation executions on user-visibility #764

Merged

Conversation

dreamofabear
Copy link
Collaborator

Enables enforcement user gesture constraints in use cases like amp-script.

Context: ampproject/amphtml#26375

}
operationStart = executor.execute(mutationArray, operationStart);
operationStart = executor.execute(mutationArray, operationStart, allow);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of preventing the mutation within each executor, could we stop execution here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, it's not the prettiest... we do need the return value of execute() for the next start position however.

I also tried adding a new interface method nextPosition(): number that just returns the next start position:

if (allow) { 
  operationStart = executor.execute(mutationArray, operationStart);
} else {
  operationStart = executor.nextPosition(mutationArray, operationStart);
}

But that resulted in a lot of code duplication for more complex command executors, like here:

const addEventListenerCount = mutations[startPosition + EventSubscriptionMutationIndex.AddEventListenerCount];
const removeEventListenerCount = mutations[startPosition + EventSubscriptionMutationIndex.RemoveEventListenerCount];
const addEventListenersPosition =
startPosition + EventSubscriptionMutationIndex.Events + removeEventListenerCount * REMOVE_EVENT_SUBSCRIPTION_LENGTH;
const endPosition =
startPosition +
EventSubscriptionMutationIndex.Events +
addEventListenerCount * ADD_EVENT_SUBSCRIPTION_LENGTH +
removeEventListenerCount * REMOVE_EVENT_SUBSCRIPTION_LENGTH;

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, didnt remember that detail.

@dreamofabear dreamofabear merged commit dbcb8d6 into ampproject:master Jan 21, 2020
@dreamofabear dreamofabear deleted the filter-mutations-on-visibility branch January 21, 2020 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants