cycle-web-extensions
Cycle.js drivers to use in Chrome extensions and WebExtensions.
Forked from cycle-extensions to rewrite it with xstream. Additionally support for the tabs
and windows
APIs was added, and the MessagesDriver
now supports more than one simultaneous connection.
Drivers
MessagesDriver
In the Web Extension architecture, logic and state both live in a long-running background page. The user interface lives in a separate page called a popup. The two pages communicate by passing messages between each other. The background page awaits connections; the popup initiates them.
messagesDriver
accepts a stream of messages to send to the other page and returns a stream of messages received from the other page.
makeMessagesDriver
takes a single named argument, shouldInitiate
. Set it to false
in the background page and true
in any other pages.
Here's an example of a simple counter. Notice that when the popup opens, it sends a request for the current state to the background page. The response it receives creates the first frame of DOM.
{ const initialState = count: 0 const state$ = messages$ return messages: xs } // and in your popup script { const count$ = // Why no pluck in xstream? return messages: xs DOM: count$ } { const increment$ = DOM const decrement$ = DOM return messages: xs }
WindowsDriver
- TODO: Document this
TabsDriver
- TODO: Document this
To see a real extension written with these drivers, check out nspaeth/tab-manager.
Installation
yarn add cycle-web-extensions