Comments (7)
What I would to achieve is:
- the iframe do login and set the token
- the parent observe for the message received and get it.
In other word what I would avoid to do is:
public ngAfterViewInit(): void {
this.main().then((ifr: any) => {
setInterval(() => {
const api = Comlink.proxy(ifr.contentWindow);
(api as any).CommunicationChannel.getInstance().then((_instance) => {
_instance.getUserToken().then(res => console.log(res));
});
}, 1000);
});
}
private main(): Promise<any> {
const ifr = document.querySelector('iframe');
return new Promise((resolve) => ifr.onload = () => {
resolve(ifr);
});
}
from comlink.
Ah, good catch. I was aware but forgot to document it in the README.
As of now, function parameters need to be either structurally cloneable or transferable. Functions are neither. Therefore your callback won’t work. I am working on a good solution, but it’s not possible as of now.
(If you wanna hack for a bit: You could use Comlink in both directions. Expose your callback to the iframe and hook it up to the Observable.
from comlink.
I updated the README. Thanks for giving Comlink a spin! @daniele-zurico. I’ll get to this issue pretty quickly I reckon – it’s a central use-case.
I want to ask one thing of you, tho: Could you reduce your test cases in the future? I really can’t do much with snippets that use Angular and potentially other libraries or frameworks. The fewer the dependencies and SLOCs, the better :)
from comlink.
Oh sure.
I was trying to put entire snippet to make my code as much as possible easy to understand for you showing the part involved.
My plan is to create a post to show how to use this library and honestly I’m almost done with the code.
I just need to find the time to write the post and I think that will be useful for everyone because honestly I think that in the doc is not so easy to understand ( maybe is just me ).
However if you prefer, when the post is ready, you can link to it
from comlink.
This has been fixed in 2191276 (included in Comlink v2.1.0)
You only need to make sure you wrap your callbacks in proxyValue
.
Just keep in mind that these callbacks will end up being asynchronous functions on the other end, I so I am not sure if RxJS will handle this correctly by default. Enjoy!
from comlink.
Running some tests with comlink...I tried passing an Observable object to the child iframe and then in the child I subscribed to that observable. Calling .subscribe(...) produced an error.
Parent:
await instance.proxyValues(Comlink.proxyValue({
preferences$: this._getGlobalPreferencesObservable()
}));
Child iFrame:
await preferences$.subscribe(v => ... );
from comlink.
Your callback needs to be wrapped into proxyValue
.
await preferences$.subscribe(Comlink.proxyValue(v => ... ));
from comlink.
Related Issues (20)
- Web Worker Hangs if Imported File Contains Top-Level `Await` HOT 6
- Service worker example: stops working when SW is suspended HOT 9
- Set operation is not awaitable HOT 2
- Possible to communicate between web workers? HOT 1
- How to transfer result buffers HOT 2
- [feat] DeasyncEndpoint HOT 2
- Move from Karma to Playwright? HOT 1
- Do I need to use transfer inside a proxy? HOT 1
- Add support for async transferHandle serializer/deserializer HOT 2
- Significant performance optimizations possible in `requestResponseMessage` HOT 4
- Push notifications from web worker HOT 5
- Memory leak when terminating worker with ongoing call HOT 2
- Worker Pool for similar tasks HOT 2
- Sharing constructed objects within a remote context HOT 1
- How to implement comlink in Next.js 14 App Route HOT 2
- Feature request: Automatic proxy of arguments HOT 3
- Having issues when using comlink with react (storing in react state) HOT 3
- Exposed function deadlocks if called too early
- Returning a collection - transferHandlers to be called
- How to prevent auto `releaseProxy`?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comlink.