-
Notifications
You must be signed in to change notification settings - Fork 11
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
refactoring #26
refactoring #26
Conversation
54a17cd
to
80ba50b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reviewing the PR, as you suggested in the PR description, I would also go ahead in a further refactor (in a different PR) extracting the Session
concept to its own class in order to manage the webrtcSwarm
connection and the underlying signalhub
.
This way we would be leaving the P2PEditor
class with the bare minimum business logic. It would act just as an orchestrator bewteen the differen pieces (Session
, Editor
, and ChangeLog
).
Changes suggested in order to keep a minimum structure while firing events. Very good job @santakadev! 🙌
Thank you @JavierCane for your feedback! I'll apply your suggested naming improvements and merge this PR to master. |
Why refactor codebase?
Right now there are too many responsabilities and IO (storage, editor, network and DOM) in the same module. This makes testing really hard and it is not clear what the application is doing.
The idea behind this PR is split this module and create some abstractions to make testing and future development easier.
For all that, I think that this codebase refactor is a must before start milestone 1.1 development.
What I have done?
Two things:
Added abstractions:
P2PFile
. Represents the storage of a source code file via deltas. Coupled to hypercore and simple-peer for replication, but decoupled from webrtc-swarm, signalhub and ace. This abstraction can help us in the future when dealing with multiple files.Editor
. Wrapper of ACE editor.Aditional concepts added:
session
: represents the current coding sessionsessionId
: id of the session.follower
: represents the peers that are following the session (read only)Things I'm not sure about
Add
Net
abstractionI've the tentation of making another abstraction called
Net
, that holds the webrtc connection via signalhub and webrtc-swarm. But for now, I think that I can leave it as it is, and reconsider it when implementing #9 Use UUIDs as session IDs and #7 Connected users listWhere to put browser IO (console, window)
I'm not happy about having URL sessionId extration/addition outside
P2PEditor
class. Currently is in index.js file, but I think that it must belong to P2PEditor class.I have done this to have the browser IO (window and console) in another module. This is not enterely true, beacuse ACE is doing browser IO.
The two alternatives that I have in mind:
Session
(currentP2PEditor
class), and put all the index.js code in a class calledP2PEditor
. In this case, P2PEditor will be holder of the session and will make browser IO based on the Session dispatched events. But I think that session is something that never changes until you exit the window. I don't imagine a feature in witch I switch to another sessión with other peers and file without leaving the browser window.P2PEditor
. This way all the logic is insideP2PEditor
class, but without introducing another abstraction.