Open
Conversation
franleplant
commented
Dec 27, 2020
src/Bridge.ts
Outdated
| } | ||
|
|
||
| emitToRemote(eventName: string, data?: unknown): void { | ||
| debug(`emit "%s" with data %O`, eventName, data); |
Owner
Author
There was a problem hiding this comment.
since Bridge is a module that is going to be used from both "parent" and "child" perhaps we want to make it an instance variable with a variable prefix so that we get differentiated output when debugging
franleplant
commented
Dec 27, 2020
| error, | ||
| } as IGetResponse); | ||
| } | ||
| } |
Owner
Author
There was a problem hiding this comment.
I really like how simple this module got
franleplant
commented
Dec 27, 2020
src/Bridge.ts
Outdated
| property, | ||
| value, | ||
| error, | ||
| } as IGetResponse); |
Owner
Author
There was a problem hiding this comment.
I'd like a more structured approach to event creation, i.e. this could probably be abstracted like this.emitToRemote(...events.getResponse({id, property, value, error}))
256b464 to
bc65e5c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a rough draft of some of the things discussed in #10
Unordered comments:
localHandleandremoteHandlebut I ended up reverting to a simple shallower structure, I did incorporate the concepts though:emitToRemoteandemitToLocalare the main replacements, theremoteHandle.addEventListeneris replaced byBridge.onand all the event methods that Emittery provides, we might be able to make these things a bit more explicit but I think it has a good balance between explicitness, simplicity and clarity.Bridgeclass. It is not the main host of all the wrapping that we do on top ofonmessageandpostMessage, it is an event emitter (Emittery) and it provides bidirectional remote method calling (it both can call a remote bridge methods via .get and also hosts methods that can be called by another remote bridge instance). There's no concept of Child or Parent at this point since both sides of the "Bridge" do exactly the same.ParentandChildadd the handshake mechanisms on top of the primitives that Bridge provides (I love this structure).Bridgehas a similar interface to Post-me Parent/Childhandshake (localWindow, remoteWindow, remoteOrigin, methods/models)I left a bunch of
TODOsor comments inline in the code, I didn't got all the way with refactors and still a lot left TODO, for example, for speed sake I keptgetinstead ofcallwhich I think it is a better concept to use.@alesgenova feel free to do whatever with this PR