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

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

Closed
chong-z opened this issue May 5, 2016 · 4 comments
Closed

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

chong-z opened this issue May 5, 2016 · 4 comments

Comments

@chong-z
Copy link

chong-z commented May 5, 2016

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)?

@garykac
Copy link
Owner

garykac commented May 5, 2016

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.

@chong-z
Copy link
Author

chong-z commented May 5, 2016

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
Owner

garykac commented May 5, 2016

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();
    };

@garykac
Copy link
Owner

garykac commented Apr 25, 2017

This issue was moved to w3c/staticrange#2

@garykac garykac closed this as completed Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants