Skip to content

[web-animations-1] Drop the *ReadOnly interfaces #2068

@birtles

Description

@birtles

From @birtles on April 7, 2017 6:27

Originally we introduced the *ReadOnly interfaces for CSS. The logic went something like this:

  • It's pretty much impossible to map changes made via API back to style (we tried, and there were lots of cases where it's just not clear what the expected behavior should be, particularly when the list length changes.)
  • So we decided to make it a one-way mapping, i.e. style updates the API objects but changing the objects doesn't update style.
  • As a result you need to know when an object gets a particular timing property from style and when it gets it from the API.
  • We tried doing this on a property-by-property basis but it leads to a very confusing API. How do you tell which properties you've overridden? How do you reset them so that they start reflecting style again? Do we add three methods per property?
  • Instead we opted for an API where you very deliberately have to break from style as follows:
const animation = div.getAnimations()[0];
animation.effect = new KeyframeEffect(animation.effect); // Make a mutable copy
// Now you can tweak it and its obvious that changes to style do not apply
effect.timing.duration = 3000; // This works
div.style.animationDuration = '4s'; // This doesn't

However, in #168 I'm proposing we simplify the timing interfaces to have only:

animation.effect.getTiming();
animation.effect.setTiming(); // Resets all properties to their defaults
animation.effect.setTimingProperty({ duration: 3000 }; // Overrides a single property

The last one is basically equivalent to:

effect.setTiming(Object.assign(effect.getTiming(), { duration: 3000 }));

I'm now wondering if there's some way we can exploit this setup (and similarly setKeyframes()) to signal which properties you want to override. Perhaps we could change the timing dictionary to have default values which we interpret as the initial value for script-generated animations and the style-specified value for CSS animations/transitions such that setTiming() resets everything?

That would certainly be nicer for authors: being able to override the delay of a single instance of a CSS animation programmatically is certainly something I've wanted to do, and it would be nice not to have to completely divorce it from style changes in order to do so. It would also avoid some of the confusion and complexity around the *ReadOnly interfaces so it's probably worth considering at least.

Copied from original issue: w3c/web-animations#185

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions