Skip to content

File loading#17

Open
Azeirah wants to merge 7 commits intoharc:masterfrom
Azeirah:fileLoading
Open

File loading#17
Azeirah wants to merge 7 commits intoharc:masterfrom
Azeirah:fileLoading

Conversation

@Azeirah
Copy link
Copy Markdown
Contributor

@Azeirah Azeirah commented Jul 27, 2015

This pull request should be merged after the "fixes" one.

In this pull request, I've added the ability to load files by passing a filename to the node server.js filename.js command. This textfile will then be read, and sent to all open editors, that's not intended behavior, but that's how it works right now.

What I've done is, I've made a very light abstraction over websockets, to make it easy to work with. The server-side one is server/channel.js and the client-side one is lib/channel.js.

server/FileLoader.js does the actual work on the server side. Whenever a new websocket connection gets established between a Moonchild instance and the server, if the server received a file via the commandline, then it opens that file and sends a "fileLoad" event using the channel to all clients.

The client then handles this "fileLoad" event in editor/loadFile.js. On "fileLoad", it simply sets the editor content to the received content.

@pdubroy
Copy link
Copy Markdown
Collaborator

pdubroy commented Jul 28, 2015

I'll take a look at this tomorrow. If you have a chance, would you mind re-syncing with the latest from cdglabs:master and uploading a new PR that only includes the file loading changes? It's a bit hard to review this way, and I'm not quite sure what the history will look like if I merge it like this...but I'm not an expert on GitHub PRs.

@Azeirah
Copy link
Copy Markdown
Contributor Author

Azeirah commented Jul 28, 2015

Yeah I expected that Github would show this PR without the first three commits after the first merge. Apparently it doesn't do that. It's why I didn't make a PR for the file saving yet either.

…leLoading

Merge older changes into fileLoading
@Azeirah
Copy link
Copy Markdown
Contributor Author

Azeirah commented Jul 28, 2015

Oh alright, I've merged cdglabs/master onto fileLoading, and github automatically edited this PR.

Comment thread editor/loadFile.js Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is unused.

Comment thread common/channel.js Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be tempted to pass the type in as an argument -- that way it's clear at the call sites what kind of channel you are instantiating. It's a little confusing that the type of channel is determined not by the value of any of the arguments, but by the type of the argument. I think passing in the type as a string would make it a bit less confusing.

Another approach would be to create a ClientChannel and a ServerChannel constructor, and export only those constructors -- they could call the Channel constructor with the appropriate args. I'm fine with whatever you prefer though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the way it currently is feels a little awkward, I don't like different constructors, because It's supposed to be the same api on the server and on the client.

Maybe something like this?

// client
var channel = new Channel({
  type: Channel.server,
  httpServer: server
});

// client
var channel = new Channel({
  type: Channel.client,
  port: 8080
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. I would just do { type: 'server', ... }, but it's your call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants