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

fix(polyfill): missing self argument for Watcher notify callback type #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yyx990803
Copy link
Collaborator

@yyx990803 yyx990803 commented Apr 1, 2024

new Signal.subtle.Watcher(self => {
                       // ^ this currently lacks type
});

@littledan
Copy link
Member

Thanks for this correction, but I think I should just remove that parameter from the code sample instead; passing it as the this value is enough.

@raven-dever
Copy link

raven-dever commented Apr 4, 2024

Addtionally to typing, this and self seem to be passed wrong.

const w = new Signal.subtle.Watcher(function (self) {
  console.log(this === w);
  console.log(this instanceof Signal.subtle.Watcher); // both false;  same with self-Argument

  console.log(this.wrapper instanceof Signal.subtle.Watcher); // true;  wrapper is the actual watcher instance

  if (needsEnqueue) {
    needsEnqueue = false;
    queueMicrotask(processPending);
  }
});

Changing the assignment of node.consumerMarkedDirty in the constructor like this or similar fixes it.

class Watcher {
  constructor(notify: (this: Watcher, self: Watcher) => void) {
    let node = Object.create(REACTIVE_NODE);
    node.wrapper = this;
    node.consumerMarkedDirty = () => {    // change to bind and pass this
      notify.call(this, this);
    };
    node.consumerIsAlwaysLive = true;
    node.consumerAllowSignalWrites = false;
    node.producerNode = [];
    this[NODE] = node;
  }
}

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

Successfully merging this pull request may close these issues.

None yet

3 participants