Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Why would we need an empty Constructor for StaticRange? #2

Closed
garykac opened this issue Apr 25, 2017 · 3 comments
Closed

Why would we need an empty Constructor for StaticRange? #2

garykac opened this issue Apr 25, 2017 · 3 comments

Comments

@garykac
Copy link
Member

garykac commented Apr 25, 2017

From @choniong on May 5, 2016 15:15

Also According to the StaticRange.idl I found there is an empty Constructor.

But since StaticRange is immutable shouldn't the constructor be something like Constructor(optional StaticRangeInit) or Constructor(Node, unsigned long, Node, unsigned long)?

Copied from original issue: garykac/staticrange#2

@garykac
Copy link
Member Author

garykac commented Apr 25, 2017

StaticRange is immutable from the DOM perspective -- i.e., DOM mutations don't affect StaticRanges like they do for Ranges.

Whether StaticRanges are immutable from the "JavaScript object"-perspective is another issue. They could be immutable once created, but there is no need for that. Allowing the values to be manually changed after the objects is created allows the StaticRange class to be used for other purposes (e.g., the undo stack that Ryosuke mentions in the post you link to.

@garykac
Copy link
Member Author

garykac commented Apr 25, 2017

From @choniong on May 5, 2016 18:22

OK so do you mean we should change the fields in StaticRange to be not readonly? Otherwise I'm not sure how can JS manually change them without a ctor? (Range has setters)

 [Constructor,
    Exposed=Window]
 interface StaticRange {
    readonly attribute Node startContainer;
    readonly attribute unsigned long startOffset;
    readonly attribute Node endContainer;
    readonly attribute unsigned long endOffset;
    readonly attribute boolean collapsed;
    readonly attribute Node commonAncestorContainer;

@garykac
Copy link
Member Author

garykac commented Apr 25, 2017

Proposed IDL would be something like:

    [Constructor, Exposed=Window]
    interface StaticRange {
      attribute Node startContainer;
      attribute unsigned long startOffset;
      attribute Node endContainer;
      attribute unsigned long endOffset;
      readonly attribute boolean collapsed;

      void setStart(Node node, unsigned long offset);
      void setEnd(Node node, unsigned long offset);

      [NewObject] Range toRange();
    };

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant