remotestorage.js icon indicating copy to clipboard operation
remotestorage.js copied to clipboard

New API for loading the widget #2

Open lesion opened this issue 7 years ago • 0 comments

Loading widget will be usually like https://github.com/remotestorage/remotestorage.js/issues/969

But would be nice to have another way to link widget and rs when they are in different contexts (eg. WebWorker, browser plugins/extensions...), I propose (as discussed here) the following optional syntax too:

// webworker.js
import RemoteStorage from 'remotestoragejs';
let rs = new RemoteStorage();

// send message received from rs to other browser-action-popup or options page
rs.on('message', chrome.runtime.sendMessage );

//Receive messages from browser-action-popup and resend it to rs
chrome.runtime.onMessage.addListener( rs.receiveMessage );
// options.js
import Widget from 'remotestorage-widget';
let widget = new Widget();
widget.on('message', chrome.runtime.sendMessage);
chrome.runtime.onMessage.addListener( widget.receiveMessage );

this would need 2 producers and 2 consumers:

  • a new message event triggered by rs with status changes as argument (ready, done, connected) - rs producer
  • a new method receiveMessage in rs that receive event from widget (connect, disconnect, sync, etc.) - rs consumer
  • a new message event triggered by widget (connect, disconnect, sync) - widget producer
  • a new receiveMessage in widget that receive event from rs (ready, done, connected) - widget consumer

don't know if this is a good idea tho, 'cause this could complicate things a bit, so I'm not putting a milestone on this for now.

lesion avatar Apr 12 '17 14:04 lesion