-
Notifications
You must be signed in to change notification settings - Fork 15
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 proxy this for emittery #196
Conversation
I've struggled to reproduce this in Node tests. I can do it with JavaScript but whatever is happening there, TypeScript seems to fix. Without digging deeper into the Vue.js source I'm not sure what they are doing differently. Maybe somebody with better TypeScript knowledge can figure this one out. I have installed this PR into my own project and it does fix the problem. |
Not sure what's happening with the macos build, is this a new problem that's worth me digging into or something known that we can address? |
That's a problem with the nix install action. I upgraded it, that should fix it. |
Awesome, thank you! |
@ThetaSinner Why do you want an AppAgentWs to be reactive? I see that @mattyg did that in mewsfeed, but I cannot see why that's necessary there, either. It seems like the AppAgentWs can just be a variable with |
It needs to be reactive so I can initialize it in the vue app's root component. Then I can display content while waiting for it to initialize, and when its ready, reactively make it available to sub-components via provide / inject. So it needs to reactively update the client variable from I just ran into this issue in another context where I am passing the AppAgentWebsocket into new class as a constructor param, and then trying to listen to signals within that class. Unfortunately this PR doesn't seem to resolve it in that case. |
@jost-s Yes to what @mattyg said and I'm going to expand a little bit.
I'm still experimenting but I've actually already taken this a step further and wrapped the client. This lets me transparently reconnect the client which I can't do with this client because construction/connection is atomic. So I am injecting my client wrapper into the components that need it then they go ahead and render while creating a promise on |
@mattyg any chance you can point me at an example and I'll see if I can figure out why this isn't working everywhere? |
Well I tried to make an example, but it worked properly, and then I fixed it in my use case as well, so nevermind! |
@mattyg Cool okay, if it pops up again feel free to send it my way :) |
@ThetaSinner With the wrapper, do you still need the Emittery workaround? |
…h fix/emittery-loses-this-behind-proxy until PR is merged ( holochain/holochain-client-js#196 )
@ThetaSinner I suppose so. I'll merge this, thanks you for the work! |
Sorry I hadn't got to this yet but yes, the Vue proxies are deep so even with a wrapper the |
Right, okay. I have been unable to reproduce the problem too, even in a JS file using Vue's |
The code I used to test the fix is import Emittery from 'emittery';
class T extends Emittery {
constructor() {
super();
// // Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
// Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
// if (typeof this[name] === 'function') {
// this[name] = this[name].bind(this);
// }
// });
}
doOn(func) {
console.log(this);
this.on('hello', func);
}
}
let t = new Proxy(new T(), {});
t.doOn(() => {
console.log('got a hello');
});
t.emit('hello'); It can just be run with node and the fix can be commented in. I get the same Emittery error I got from a Vue app
|
Thanks for that. Do you have a clue why something like const appAgentWs = await AppAgentWs.connect(...);
const ws = ref(appAgentWs);
ws.value.client.on('signal', () => console.log('signalled'));
ws.value.client.emit('signal', ...); works? |
That does fail for me, if I do
I can then start a sandbox, run it with
The test script runs fine if I comment my fix back in |
This addresses #195