salts633 / PhotoFrame

A python/browser based digital photo frame
GNU General Public License v3.0
0 stars 1 forks source link

Refactor javascript to use a message handler #13

Closed salts633 closed 4 years ago

salts633 commented 4 years ago

The javascript would be cleaner if you had one central handler that listened to messages from the web socket. It could then have its own events, one per message type, that could be subscribed to. This would probably be cleaner than the current situation where each js function first has to check the type of the message and then has to check its value.

You could go further and have events for each setting updated, but in this case you would probably need to combine the 'update interval' and 'update interval unit' messages in to a single message. Logically this would make sense as they are both required to update the gui correctly.

salts633 commented 4 years ago

Use promises, this isn't something that should be running in the main thread.

salts633 commented 4 years ago

Moving this to the first release as I've realised it will be easy to implement #4 if this is done first

salts633 commented 4 years ago

Completed in c3a7e495cd542bf00a68765641000464a4a8f7d9, there is now a COMM global variable that can be used to send messages and a addMessageCallback function that allows callbacks to be registered for different types.