Git Product home page Git Product logo

Comments (1)

dvoytenko avatar dvoytenko commented on May 27, 2024

A possibly much simpler approach - expected mutation matching:

  1. Some internal mutations are ignored and thus can be done safely by components. These include i-amphtml attributes, --i-amphtml-x CSS vars in style, children with i-amphtml-x class or special attribute, i-amphtml-x attribute values (slot=i-amphtml-slide-1), etc. The expectation is that majority of mutations that need to be done in the light subtree can be done this way.
  2. For other light tree mutations we will require a MutationRecord to be created and pushed for the target element into the "pending set". When the MutationObserver is notified with a mutation, it can match the MutationRecord against the "pending set", and ignore the record if a matching one exists.

For instance, the component's implementation modifies the light tree:

useEffect(() => {
  const el = ref.current;

  // This record will be ignore because the attribute's value
  // starts with "i-amphtml-" prefix.
  el.setAttribute('slot', 'i-amphtml-slot1');

  // The argument is in the `MutationRecord` format.
  // The `applyMutation` will actually apply the mutation, e.g. it will
  // call `el.setAttribute('selected', '')`, but it will also record this
  // mutation record in the "pending set".
  applyMutation({target: el, type: 'attributes', attributeName: 'selected', value: ''});
});

The main idea here is that the light tree mutation are very rare and thus can take a bit more verbosity and indirection to execute to avoid confusion w.r.t. where a mutation comes from.

from amp-react-prototype.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.