proposal-signals
proposal-signals copied to clipboard
fix(polyfill): missing self argument for Watcher notify callback type
new Signal.subtle.Watcher(self => {
// ^ this currently lacks type
});
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.
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;
}
}