Commit 89d47c21 authored by Aron Carroll's avatar Aron Carroll

Rename CrossFrameBridge to Bridge

parent 72a07437
......@@ -4,7 +4,7 @@ class AnnotationUISync
###*
# @name AnnotationUISync
# @param {$window} $window An Angular window service.
# @param {CrossFrameBridge} bridge
# @param {Bridge} bridge
# @param {AnnotationSync} annotationSync
# @param {AnnotationUI} annotationUI An instance of the AnnotatonUI service
# @description
......
......@@ -14,7 +14,7 @@ Bridge = class Annotator.Plugin.Bridge extends Annotator.Plugin
discovery = new Bridge.CrossFrameDiscovery(window, opts)
opts = extract(options, 'scope')
bridge = new Bridge.CrossFrameBridge(opts)
bridge = new Bridge.Bridge(opts)
opts = extract(options, 'on', 'emit', 'formatter', 'parser')
annotationSync = new Bridge.AnnotationSync(bridge, opts)
......
class CrossFrameBridge
class Bridge
options:
# Scope identifier to distinguish this channel from any others
scope: 'crossFrameBridge'
......@@ -89,7 +89,7 @@ class CrossFrameBridge
on: (method, callback) ->
if @channelListeners[method]
throw new Error("Listener '#{method}' already bound in CrossFrameBridge")
throw new Error("Listener '#{method}' already bound in Bridge")
@channelListeners[method] = callback
for l in @links
......@@ -116,6 +116,6 @@ class CrossFrameBridge
channel = Channel.build(options)
if angular?
angular.module('h').value('CrossFrameBridge', CrossFrameBridge)
angular.module('h').value('Bridge', Bridge)
else
Annotator.Plugin.Bridge.CrossFrameBridge = CrossFrameBridge
Annotator.Plugin.Bridge.Bridge = Bridge
......@@ -4,12 +4,12 @@ class CrossFrameService
this.inject = [
'$rootScope', '$document', '$window', 'store', 'annotationUI'
'CrossFrameDiscovery', 'CrossFrameBridge',
'CrossFrameDiscovery', 'Bridge',
'AnnotationSync', 'AnnotationUISync'
]
constructor: (
$rootScope, $document, $window, store, annotationUI
CrossFrameDiscovery, CrossFrameBridge,
CrossFrameDiscovery, Bridge,
AnnotationSync, AnnotationUISync
) ->
@providers = []
......@@ -24,7 +24,7 @@ class CrossFrameService
createBridge = ->
options =
scope: 'annotator:bridge'
new CrossFrameBridge(options)
new Bridge(options)
createAnnotationSync = (bridge) ->
whitelist = ['target', 'document', 'uri']
......
......@@ -4,7 +4,7 @@ sinon.assert.expose(assert, prefix: '')
describe 'Annotator.Plugin.Bridge', ->
Bridge = null
fakeCFDiscovery = null
fakeCFBridge = null
fakeBridge = null
fakeAnnotationSync = null
sandbox = sinon.sandbox.create()
......@@ -20,7 +20,7 @@ describe 'Annotator.Plugin.Bridge', ->
startDiscovery: sandbox.stub()
stopDiscovery: sandbox.stub()
fakeCFBridge =
fakeBridge =
createChannel: sandbox.stub()
onConnect: sandbox.stub()
notify: sandbox.stub()
......@@ -32,7 +32,7 @@ describe 'Annotator.Plugin.Bridge', ->
Bridge = Annotator.Plugin.Bridge
sandbox.stub(Bridge, 'AnnotationSync').returns(fakeAnnotationSync)
sandbox.stub(Bridge, 'CrossFrameDiscovery').returns(fakeCFDiscovery)
sandbox.stub(Bridge, 'CrossFrameBridge').returns(fakeCFBridge)
sandbox.stub(Bridge, 'Bridge').returns(fakeBridge)
afterEach ->
sandbox.restore()
......@@ -48,15 +48,15 @@ describe 'Annotator.Plugin.Bridge', ->
assert.called(Bridge.CrossFrameDiscovery)
assert.calledWith(Bridge.CrossFrameDiscovery, window, server: true)
it 'instantiates the CrossFrameBridge component', ->
it 'instantiates the Bridge component', ->
createBridge()
assert.called(Bridge.CrossFrameBridge)
assert.called(Bridge.Bridge)
assert.calledWith(Bridge.CrossFrameDiscovery)
it 'passes the options along to the bridge', ->
createBridge(scope: 'myscope')
assert.called(Bridge.CrossFrameBridge)
assert.calledWith(Bridge.CrossFrameBridge, scope: 'myscope')
assert.called(Bridge.Bridge)
assert.calledWith(Bridge.Bridge, scope: 'myscope')
it 'instantiates the AnnotationSync component', ->
createBridge()
......@@ -66,7 +66,7 @@ describe 'Annotator.Plugin.Bridge', ->
formatter = (x) -> x
createBridge(formatter: formatter)
assert.called(Bridge.AnnotationSync)
assert.calledWith(Bridge.AnnotationSync, fakeCFBridge, {
assert.calledWith(Bridge.AnnotationSync, fakeBridge, {
on: sinon.match.func
emit: sinon.match.func
formatter: formatter
......@@ -82,8 +82,8 @@ describe 'Annotator.Plugin.Bridge', ->
bridge = createBridge()
bridge.pluginInit()
fakeCFDiscovery.startDiscovery.yield('SOURCE', 'ORIGIN', 'TOKEN')
assert.called(fakeCFBridge.createChannel)
assert.calledWith(fakeCFBridge.createChannel, 'SOURCE', 'ORIGIN', 'TOKEN')
assert.called(fakeBridge.createChannel)
assert.calledWith(fakeBridge.createChannel, 'SOURCE', 'ORIGIN', 'TOKEN')
describe '.destroy', ->
it 'stops the discovery of new frames', ->
......@@ -101,17 +101,17 @@ describe 'Annotator.Plugin.Bridge', ->
it 'proxies the call to the bridge', ->
bridge = createBridge()
bridge.on('event', 'arg')
assert.calledWith(fakeCFBridge.on, 'event', 'arg')
assert.calledWith(fakeBridge.on, 'event', 'arg')
describe '.notify', ->
it 'proxies the call to the bridge', ->
bridge = createBridge()
bridge.notify(method: 'method')
assert.calledWith(fakeCFBridge.notify, method: 'method')
assert.calledWith(fakeBridge.notify, method: 'method')
describe '.onConnect', ->
it 'proxies the call to the bridge', ->
bridge = createBridge()
fn = ->
bridge.onConnect(fn)
assert.calledWith(fakeCFBridge.onConnect, fn)
assert.calledWith(fakeBridge.onConnect, fn)
assert = chai.assert
sinon.assert.expose assert, prefix: null
describe 'CrossFrameBridge', ->
describe 'Bridge', ->
sandbox = sinon.sandbox.create()
createBridge = null
createChannel = null
beforeEach module('h')
beforeEach inject (CrossFrameBridge) ->
beforeEach inject (Bridge) ->
createBridge = (options) ->
new CrossFrameBridge(options)
new Bridge(options)
createChannel = ->
call: sandbox.stub()
......
......@@ -10,7 +10,7 @@ describe 'CrossFrameService', ->
fakeStore = null
fakeAnnotationUI = null
fakeCrossFrameDiscovery = null
fakeCrossFrameBridge = null
fakeBridge = null
fakeAnnotationSync = null
fakeAnnotationUISync = null
......@@ -22,7 +22,7 @@ describe 'CrossFrameService', ->
fakeAnnotationUI = {}
fakeCrossFrameDiscovery =
startDiscovery: sandbox.stub()
fakeCrossFrameBridge =
fakeBridge =
notify: sandbox.stub()
createChannel: sandbox.stub()
onConnect: sandbox.stub()
......@@ -35,8 +35,8 @@ describe 'CrossFrameService', ->
$provide.value('annotationUI', fakeAnnotationUI)
$provide.value('CrossFrameDiscovery',
sandbox.stub().returns(fakeCrossFrameDiscovery))
$provide.value('CrossFrameBridge',
sandbox.stub().returns(fakeCrossFrameBridge))
$provide.value('Bridge',
sandbox.stub().returns(fakeBridge))
$provide.value('AnnotationSync',
sandbox.stub().returns(fakeAnnotationSync))
$provide.value('AnnotationUISync',
......@@ -54,13 +54,13 @@ describe 'CrossFrameService', ->
it 'creates a new channel when the discovery module finds a frame', ->
fakeCrossFrameDiscovery.startDiscovery.yields('source', 'origin', 'token')
crossframe.connect()
assert.calledWith(fakeCrossFrameBridge.createChannel,
assert.calledWith(fakeBridge.createChannel,
'source', 'origin', 'token')
it 'queries discovered frames for metadata', ->
info = {metadata: link: [{href: 'http://example.com'}]}
channel = {call: sandbox.stub().yieldsTo('success', info)}
fakeCrossFrameBridge.onConnect.yields(channel)
fakeBridge.onConnect.yields(channel)
crossframe.connect()
assert.calledWith(channel.call, {
method: 'getDocumentInfo'
......@@ -70,7 +70,7 @@ describe 'CrossFrameService', ->
it 'updates the providers array', ->
info = {metadata: link: [{href: 'http://example.com'}]}
channel = {call: sandbox.stub().yieldsTo('success', info)}
fakeCrossFrameBridge.onConnect.yields(channel)
fakeBridge.onConnect.yields(channel)
crossframe.connect()
assert.deepEqual(crossframe.providers, [
{channel: channel, entities: ['http://example.com']}
......@@ -82,5 +82,5 @@ describe 'CrossFrameService', ->
message = {method: 'foo', params: 'bar'}
crossframe.connect() # create the bridge.
crossframe.notify(message)
assert.calledOn(fakeCrossFrameBridge.notify, fakeCrossFrameBridge)
assert.calledWith(fakeCrossFrameBridge.notify, message)
assert.calledOn(fakeBridge.notify, fakeBridge)
assert.calledWith(fakeBridge.notify, message)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment